mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
Add timeout kwarg for polling
This commit is contained in:
parent
e1eed6ccb7
commit
b07352e1d4
1 changed files with 6 additions and 4 deletions
|
|
@ -21,7 +21,7 @@ def _setup_callbacks(executor, on_startup=None, on_shutdown=None):
|
||||||
|
|
||||||
|
|
||||||
def start_polling(dispatcher, *, loop=None, skip_updates=False, reset_webhook=True,
|
def start_polling(dispatcher, *, loop=None, skip_updates=False, reset_webhook=True,
|
||||||
on_startup=None, on_shutdown=None):
|
on_startup=None, on_shutdown=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
Start bot in long-polling mode
|
Start bot in long-polling mode
|
||||||
|
|
||||||
|
|
@ -31,11 +31,12 @@ def start_polling(dispatcher, *, loop=None, skip_updates=False, reset_webhook=Tr
|
||||||
:param reset_webhook:
|
:param reset_webhook:
|
||||||
:param on_startup:
|
:param on_startup:
|
||||||
:param on_shutdown:
|
:param on_shutdown:
|
||||||
|
:param timeout:
|
||||||
"""
|
"""
|
||||||
executor = Executor(dispatcher, skip_updates=skip_updates, loop=loop)
|
executor = Executor(dispatcher, skip_updates=skip_updates, loop=loop)
|
||||||
_setup_callbacks(executor, on_startup, on_shutdown)
|
_setup_callbacks(executor, on_startup, on_shutdown)
|
||||||
|
|
||||||
executor.start_polling(reset_webhook=reset_webhook)
|
executor.start_polling(reset_webhook=reset_webhook, timeout=timeout)
|
||||||
|
|
||||||
|
|
||||||
def start_webhook(dispatcher, webhook_path, *, loop=None, skip_updates=None,
|
def start_webhook(dispatcher, webhook_path, *, loop=None, skip_updates=None,
|
||||||
|
|
@ -223,18 +224,19 @@ class Executor:
|
||||||
|
|
||||||
web.run_app(self._web_app, **kwargs)
|
web.run_app(self._web_app, **kwargs)
|
||||||
|
|
||||||
def start_polling(self, reset_webhook=None):
|
def start_polling(self, reset_webhook=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
Start bot in long-polling mode
|
Start bot in long-polling mode
|
||||||
|
|
||||||
:param reset_webhook:
|
:param reset_webhook:
|
||||||
|
:param timeout:
|
||||||
"""
|
"""
|
||||||
self._prepare_polling()
|
self._prepare_polling()
|
||||||
loop: asyncio.AbstractEventLoop = self.loop
|
loop: asyncio.AbstractEventLoop = self.loop
|
||||||
|
|
||||||
try:
|
try:
|
||||||
loop.run_until_complete(self._startup_polling())
|
loop.run_until_complete(self._startup_polling())
|
||||||
loop.create_task(self.dispatcher.start_polling(reset_webhook=reset_webhook))
|
loop.create_task(self.dispatcher.start_polling(reset_webhook=reset_webhook, timeout=timeout))
|
||||||
loop.run_forever()
|
loop.run_forever()
|
||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit):
|
||||||
# loop.stop()
|
# loop.stop()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue