-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Open
Labels
core[Component] This issue is related to the core interface and implementation[Component] This issue is related to the core interface and implementation
Description
asyncio.create_task must have a strong reference otherwise they can get garbage collected.
https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task:
Important Save a reference to the result of this function, to avoid a task disappearing mid-execution. The event loop only keeps weak references to tasks. A task that isn’t referenced elsewhere may get garbage collected at any time, even before it’s done. For reliable “fire-and-forget” background tasks, gather them in a collection:
adk-python/src/google/adk/runners.py
Lines 413 to 424 in 05aa3fa
# Run compaction after all events are yielded from the agent. | |
# (We don't compact in the middle of an invocation, we only compact at the end of an invocation.) | |
if self.app and self.app.events_compaction_config: | |
logger.info('Running event compactor.') | |
# Run compaction in a separate task to avoid blocking the main thread. | |
# So the users can still finish the event loop from the agent while the | |
# compaction is running. | |
asyncio.create_task( | |
_run_compaction_for_sliding_window( | |
self.app, session, self.session_service | |
) | |
) |
Note that the create_task result is not stored.
Metadata
Metadata
Assignees
Labels
core[Component] This issue is related to the core interface and implementation[Component] This issue is related to the core interface and implementation