You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using the langgraph library and running asynchronous execution inside the run_graph() function, which awaits graph.ainvoke().
I create task with asyncio.create_task(run_graph()) and call cancel() on it when needed. Although the cancellation log in run_graph() is printed properly, the internal Task asyncQueue.waiting() created by langgraph remains pending and does not get cancelled properly.
[ERROR] asyncio: Task was destroyed but it is pending!
source_traceback: Object created at (most recent call last):
File "<string>", line 1, in <module>
File ".pyenv/versions/3.11.4/lib/python3.11/multiprocessing/spawn.py", line 120, in spawn_main
exitcode = _main(fd, parent_sentinel)
File ".pyenv/versions/3.11.4/lib/python3.11/multiprocessing/spawn.py", line 133, in _main
return self._bootstrap(parent_sentinel)
File ".pyenv/versions/3.11.4/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap
self.run()
File ".pyenv/versions/3.11.4/lib/python3.11/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File ".venv/lib/python3.11/site-packages/uvicorn/_subprocess.py", line 80, in subprocess_started
target(sockets=sockets)
File ".venv/lib/python3.11/site-packages/uvicorn/server.py", line 67, in run
return asyncio.run(self.serve(sockets=sockets))
File ".pyenv/versions/3.11.4/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
File ".pyenv/versions/3.11.4/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
File ".venv/lib/python3.11/site-packages/langgraph/pregel/main.py", line 3112, in ainvoke
async for chunk in self.astream(
File ".venv/lib/python3.11/site-packages/langgraph/pregel/main.py", line 2939, in astream
async for _ in runner.atick(
File ".venv/lib/python3.11/site-packages/langgraph/pregel/_runner.py", line 380, in atick
futures[get_waiter()] = None
File ".venv/lib/python3.11/site-packages/langgraph/pregel/main.py", line 2927, in get_waiter
return aioloop.create_task(stream.wait())
task: <Task pending name='Task-167' coro=<AsyncQueue.wait() running at .venv/lib/python3.11/site-packages/langgraph/_internal/_queue.py:33> wait_for=<Future pending cb=[Task.task_wakeup()] created at .venv/lib/python3.11/site-packages/langgraph/_internal/_queue.py:28> created at .venv/lib/python3.11/site-packages/langgraph/pregel/main.py:2927>
The run_graph() coroutine catches the cancellation and logs it, but the internal asyncQueue.waiting() Task remains alive.
Any advice on how to properly cancel and cleanup asyncQueue.waiting() Task or if there is a recommended way to manage graceful shutdown with langgraph would be appreciated.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I am using the langgraph library and running asynchronous execution inside the run_graph() function, which awaits graph.ainvoke().
I create task with asyncio.create_task(run_graph()) and call cancel() on it when needed. Although the cancellation log in run_graph() is printed properly, the internal Task asyncQueue.waiting() created by langgraph remains pending and does not get cancelled properly.
The run_graph() coroutine catches the cancellation and logs it, but the internal asyncQueue.waiting() Task remains alive.
Any advice on how to properly cancel and cleanup asyncQueue.waiting() Task or if there is a recommended way to manage graceful shutdown with langgraph would be appreciated.
Environment
Beta Was this translation helpful? Give feedback.
All reactions