Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I have created a bot, and I need an extern service to run concurrently to the bot.
My issue is that if I execute this code :

import asyncio

async def main():
    bot = TheTelegramBotIHaveCreated(TOKEN)
    asyncio.create_task(run_concurrent_service())
    bot.application().run_polling()

asyncio.run(main())

I get this error:

Traceback (most recent call last):
  File "/home/kaki/.local/lib/python3.10/site-packages/telegram/ext/_application.py", line 1112, in __run
    loop.run_until_complete(self.shutdown())
  File "/usr/lib/python3.10/asyncio/base_events.py", line 625, in run_until_complete
    self._check_running()
  File "/usr/lib/python3.10/asyncio/base_events.py", line 584, in _check_running
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running

How can I launch a bot without creating a new event loop?

You must be logged in to vote

Replies: 1 comment

Comment options

Hi. Please have a look at https://github.com/python-telegram-bot/python-telegram-bot/wiki/Frequently-requested-design-patterns#running-ptb-alongside-other-asyncio-frameworks

You must be logged in to vote
0 replies
Answer selected by Kaki-In
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
⁉️
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.