Fix _process_polling_updates being garbage collected (#1328)

This commit is contained in:
Sergey Akentev 2023-10-06 23:43:21 +03:00 committed by GitHub
parent 88baf0b582
commit 192a5e5e64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -88,6 +88,7 @@ class Dispatcher(DataMixin, ContextInstanceMixin):
self._polling = False
self._closed = True
self._dispatcher_close_waiter = None
self._polling_tasks = set()
self._setup_filters()
@ -395,7 +396,9 @@ class Dispatcher(DataMixin, ContextInstanceMixin):
log.debug(f"Received {len(updates)} updates.")
offset = updates[-1].update_id + 1
asyncio.create_task(self._process_polling_updates(updates, fast))
polling_task = asyncio.create_task(self._process_polling_updates(updates, fast))
self._polling_tasks.add(polling_task)
polling_task.add_done_callback(self._polling_tasks.discard)
if relax:
await asyncio.sleep(relax)