mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 10:56:29 +03:00
python: save references to asyncio tasks to avoid GC
Otherwise the task may be garbage collected and cancelled. See <https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task> for reference.
This commit is contained in:
@@ -64,7 +64,8 @@ async def main():
|
||||
|
||||
bot = Bot(account, hooks)
|
||||
if not await bot.is_configured():
|
||||
asyncio.create_task(bot.configure(email=sys.argv[1], password=sys.argv[2]))
|
||||
# Save a reference to avoid garbage collection of the task.
|
||||
_configure_task = asyncio.create_task(bot.configure(email=sys.argv[1], password=sys.argv[2]))
|
||||
await bot.run_forever()
|
||||
|
||||
|
||||
|
||||
@@ -104,7 +104,8 @@ async def _run_cli(
|
||||
if not await client.is_configured():
|
||||
assert args.email, "Account is not configured and email must be provided"
|
||||
assert args.password, "Account is not configured and password must be provided"
|
||||
asyncio.create_task(client.configure(email=args.email, password=args.password))
|
||||
# Save a reference to avoid garbage collection of the task.
|
||||
_configure_task = asyncio.create_task(client.configure(email=args.email, password=args.password))
|
||||
await client.run_forever()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user