mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 02:03:04 +00:00
Rename run to run_polling
This commit is contained in:
parent
02cefa1cf3
commit
9dc1e9ff1a
2 changed files with 6 additions and 4 deletions
|
|
@ -121,7 +121,7 @@ class Dispatcher(Router):
|
||||||
await self.process_update(update=update, bot=bot, **kwargs)
|
await self.process_update(update=update, bot=bot, **kwargs)
|
||||||
|
|
||||||
async def _run_polling(self, *bots: Bot, **kwargs: Any) -> None:
|
async def _run_polling(self, *bots: Bot, **kwargs: Any) -> None:
|
||||||
async with self._running_lock: # Prevent to run this method twice at a once
|
async with self._running_lock: # Prevent to run_polling this method twice at a once
|
||||||
workflow_data = {"dispatcher": self, "bots": bots, "bot": bots[-1]}
|
workflow_data = {"dispatcher": self, "bots": bots, "bot": bots[-1]}
|
||||||
workflow_data.update(kwargs)
|
workflow_data.update(kwargs)
|
||||||
await self.emit_startup(**workflow_data)
|
await self.emit_startup(**workflow_data)
|
||||||
|
|
@ -129,7 +129,7 @@ class Dispatcher(Router):
|
||||||
try:
|
try:
|
||||||
coro_list = []
|
coro_list = []
|
||||||
for bot in bots:
|
for bot in bots:
|
||||||
async with bot.context():
|
async with bot.context(auto_close=False):
|
||||||
user: User = await bot.me()
|
user: User = await bot.me()
|
||||||
loggers.dispatcher.info(
|
loggers.dispatcher.info(
|
||||||
"Run polling for bot @%s id=%d - %r",
|
"Run polling for bot @%s id=%d - %r",
|
||||||
|
|
@ -140,10 +140,12 @@ class Dispatcher(Router):
|
||||||
coro_list.append(self._polling(bot=bot, **kwargs))
|
coro_list.append(self._polling(bot=bot, **kwargs))
|
||||||
await asyncio.gather(*coro_list)
|
await asyncio.gather(*coro_list)
|
||||||
finally:
|
finally:
|
||||||
|
for bot in bots:
|
||||||
|
await bot.close()
|
||||||
loggers.dispatcher.info("Polling stopped")
|
loggers.dispatcher.info("Polling stopped")
|
||||||
await self.emit_shutdown(**workflow_data)
|
await self.emit_shutdown(**workflow_data)
|
||||||
|
|
||||||
def run(self, *bots: Bot, **kwargs: Any):
|
def run_polling(self, *bots: Bot, **kwargs: Any):
|
||||||
"""
|
"""
|
||||||
Run many bots with polling
|
Run many bots with polling
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -192,5 +192,5 @@ class TestDispatcher:
|
||||||
def test_run(self, bot: MockedBot):
|
def test_run(self, bot: MockedBot):
|
||||||
dispatcher = Dispatcher()
|
dispatcher = Dispatcher()
|
||||||
with patch("aiogram.dispatcher.dispatcher.Dispatcher._run_polling") as patched_run_polling:
|
with patch("aiogram.dispatcher.dispatcher.Dispatcher._run_polling") as patched_run_polling:
|
||||||
dispatcher.run(bot)
|
dispatcher.run_polling(bot)
|
||||||
patched_run_polling.assert_awaited_once()
|
patched_run_polling.assert_awaited_once()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue