Skip to content

Commit ef904a4

Browse files
committed
commands issue
1 parent f025c9b commit ef904a4

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

agents/matlab/matlab_agent/src/core/interactive.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from ..utils.create_response import create_response
1818
from ..utils.logger import get_logger
1919
from ..utils.performance_monitor import PerformanceMonitor
20-
from ..utils.commands import CommandRegistry
2120
from ..utils.constants import (
2221
ACCEPT_TIMEOUT,
2322
BUFFER_SIZE,
@@ -247,9 +246,6 @@ def run(self, pm: PerformanceMonitor, msg_dict: Dict[str, Any]) -> None:
247246
method, _ , body = ch.basic_get(
248247
queue=qname, auto_ack=True)
249248
while method:
250-
if CommandRegistry.should_stop():
251-
logger.info("[INTERACTIVE] Stop command received")
252-
return
253249
frame = _parse_frame(body)
254250
if frame:
255251
# Send the inputs to MATLAB
@@ -269,7 +265,6 @@ def run(self, pm: PerformanceMonitor, msg_dict: Dict[str, Any]) -> None:
269265
logger.info("[INTERACTIVE] Interrupted by user")
270266
finally:
271267
pm.record_simulation_complete()
272-
CommandRegistry.reset()
273268

274269
def close(self) -> None:
275270
"""Close the TCP servers"""

agents/matlab/matlab_agent/src/core/streaming.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from ..utils.create_response import create_response
2121
from ..utils.logger import get_logger
2222
from ..utils.performance_monitor import PerformanceMonitor
23-
from ..utils.commands import CommandRegistry
2423

2524
# Configure logger
2625
logger = get_logger()
@@ -301,9 +300,6 @@ def run(self, inputs: Dict[str, Any], performance_monitor) -> None:
301300
buffer = b""
302301
sequence = 0
303302
while True:
304-
if CommandRegistry.should_stop():
305-
logger.info("Stopping streaming simulation on command")
306-
break
307303
chunk = self.connection.connection.recv(4096)
308304
if not chunk:
309305
logger.debug("Connection closed")
@@ -320,7 +316,6 @@ def run(self, inputs: Dict[str, Any], performance_monitor) -> None:
320316
except json.JSONDecodeError as e:
321317
logger.warning("Invalid JSON: %s", str(e))
322318
performance_monitor.record_simulation_complete()
323-
CommandRegistry.reset()
324319
except socket.timeout as e:
325320
logger.error("Connection timeout: %s", str(e))
326321
raise MatlabStreamingError("Connection timeout") from e
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
import threading
22

3-
class CommandRegistry:
4-
"""Global command registry for simulation control."""
3+
class StopRequested(Exception):
4+
"""Raised to unwind the stack when a stop is requested."""
5+
pass
56

7+
class CommandRegistry:
68
_stop_event = threading.Event()
79

810
@classmethod
911
def stop(cls) -> None:
10-
"""Signal that the current simulation should stop."""
1112
cls._stop_event.set()
1213

1314
@classmethod
1415
def reset(cls) -> None:
15-
"""Clear the stop flag, allowing simulations to run."""
1616
cls._stop_event.clear()
1717

1818
@classmethod
1919
def should_stop(cls) -> bool:
20-
"""Check whether a stop command was issued."""
21-
return cls._stop_event.is_set()
20+
return cls._stop_event.is_set()
21+
22+
@classmethod
23+
def wait(cls, timeout: float) -> bool:
24+
"""Block up to `timeout` seconds. Return True if stop requested."""
25+
return cls._stop_event.wait(timeout)

0 commit comments

Comments
 (0)