Skip to content

Commit

Permalink
Cancel old process_output coro on new message
Browse files Browse the repository at this point in the history
  • Loading branch information
ajhai committed Oct 23, 2024
1 parent 602691f commit 7126458
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions llmstack/apps/runner/agent_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,15 @@ def reset(self):

# If there is no running event loop, create one and run the task
try:
asyncio.get_running_loop()
loop = asyncio.get_running_loop()
logger.info("Running process output task in existing event loop")
self._process_output_task = loop.create_task(self._process_output())
except RuntimeError:
logger.info("No running event loop, creating one and running process output task")
run_coro_in_new_loop(self._process_output())
else:
logger.info("Running process output task")
self._process_output_task = asyncio.create_task(self._process_output())
self._process_output_task = run_coro_in_new_loop(self._process_output())

def on_stop(self):
super().on_stop()
if self._process_output_task:
self._process_output_task.cancel()
self._process_output_task = None

0 comments on commit 7126458

Please sign in to comment.