Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bot,dispatcher): do not use _MainThread event loop #397

Merged
merged 5 commits into from Sep 13, 2020

Conversation

uwinx
Copy link
Contributor

@uwinx uwinx commented Aug 2, 2020

Description

on ::Bot, ::Dispatcher initializators

Fixes #365

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • ~Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Test:

The following should work

from aiogram import Bot, Dispatcher, types

bot = Bot(TOKEN)
dp = Dispatcher(bot=bot)


@dp.message_handler()
async def echo_processor(event: types.Message):
    await event.reply(event.html_text, parse_mode=types.ParseMode.HTML)


async def main():
    await bot.send_message(CHAT_ID, "Hi!")
    try:
        await dp.start_polling()
    finally:
        await bot.close()
        await dp.wait_closed()


if __name__ == '__main__':
    import asyncio
    asyncio.run(main())

@uwinx uwinx added the bug Something is wrong with the framework label Aug 2, 2020
@uwinx uwinx requested a review from JrooTJunior August 2, 2020 10:34
@uwinx uwinx self-assigned this Aug 2, 2020
@uwinx uwinx marked this pull request as ready for review August 2, 2020 11:17
@uwinx
Copy link
Contributor Author

uwinx commented Aug 2, 2020

I'd love to get rid of loop attribute from everywhere possible, but for now we need to store it for the sake of backward compatibility 😬

@uwinx uwinx requested a review from gabbhack September 13, 2020 19:33
@JrooTJunior JrooTJunior merged commit c99b165 into dev-2.x Sep 13, 2020
uburuntu pushed a commit to uburuntu/aiogram that referenced this pull request Oct 4, 2020
* fix(bot,dispatcher): do not use _MainThread event loop on ::Bot, ::Dispatcher initializations

* fix: use more generic get approach

* docs: comments

* chore(task): asyncio.create_task comes with py3.7

* fix(dispatcher): todo
@JrooTJunior JrooTJunior deleted the fix-asyncio-loop branch May 12, 2021 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is wrong with the framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RuntimeError: Timeout context manager should be used inside a task
2 participants