Skip to content

Commit 0c32ef1

Browse files
committed
Add name to loop
1 parent 1e3b63d commit 0c32ef1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

llmstack/play/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def extract_variables(expression):
7575
return variables
7676

7777

78-
def run_coro_in_new_loop(coro):
78+
def run_coro_in_new_loop(coro, name=None):
7979
def start_loop(loop):
8080
asyncio.set_event_loop(loop)
8181
loop.run_forever()
@@ -86,8 +86,12 @@ def _done_callback(future):
8686
except CancelledError:
8787
logger.info("Task cancelled")
8888
except Exception as e:
89-
logger.exception(f"Task failed with error: {e}")
89+
logger.error(f"Task in loop {name} failed with error: {e}")
9090
finally:
91+
# Find and cancel all pending tasks before stopping the loop
92+
for task in asyncio.all_tasks(loop):
93+
task.cancel()
94+
9195
loop.stop()
9296

9397
loop = asyncio.new_event_loop()

0 commit comments

Comments
 (0)