Rename run to run_polling

This commit is contained in:
jrootjunior 2019-12-12 11:58:21 +02:00
parent 02cefa1cf3
commit 9dc1e9ff1a
2 changed files with 6 additions and 4 deletions

View file

@ -121,7 +121,7 @@ class Dispatcher(Router):
await self.process_update(update=update, bot=bot, **kwargs)
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.update(kwargs)
await self.emit_startup(**workflow_data)
@ -129,7 +129,7 @@ class Dispatcher(Router):
try:
coro_list = []
for bot in bots:
async with bot.context():
async with bot.context(auto_close=False):
user: User = await bot.me()
loggers.dispatcher.info(
"Run polling for bot @%s id=%d - %r",
@ -140,10 +140,12 @@ class Dispatcher(Router):
coro_list.append(self._polling(bot=bot, **kwargs))
await asyncio.gather(*coro_list)
finally:
for bot in bots:
await bot.close()
loggers.dispatcher.info("Polling stopped")
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

View file

@ -192,5 +192,5 @@ class TestDispatcher:
def test_run(self, bot: MockedBot):
dispatcher = Dispatcher()
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()