Skip to content

Commit

Permalink
Add a lock for the status command
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Nov 2, 2024
1 parent b5ba879 commit b69940a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Next version

### ✨ Improved

* Add a lock for the status command to prevent multiple concurrent requests.

### ⚙️ Engineering

Use `uv` for packaging.
Expand Down
2 changes: 2 additions & 0 deletions python/lvmecp/actor/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def __init__(
else:
self.plc = plc

self.lock = asyncio.Lock()

async def start(self, **kwargs):
"""Starts the actor."""

Expand Down
21 changes: 11 additions & 10 deletions python/lvmecp/actor/commands/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ async def status(command: ECPCommand, no_registers: bool = False):

plc = command.actor.plc

if no_registers is False:
command.info(registers=(await plc.read_all_registers(use_cache=False)))

modules: list[PLCModule] = [plc.dome, plc.safety, plc.lights]
await asyncio.gather(
*[
module.update(force_output=True, command=command, use_cache=True)
for module in modules
]
)
async with command.actor.lock:
if no_registers is False:
command.info(registers=(await plc.read_all_registers(use_cache=False)))

modules: list[PLCModule] = [plc.dome, plc.safety, plc.lights]
await asyncio.gather(
*[
module.update(force_output=True, command=command, use_cache=True)
for module in modules
]
)

command.info(
o2_percent_utilities=plc.safety.o2_level_utilities,
Expand Down

0 comments on commit b69940a

Please sign in to comment.