Is there a way to run a concurrent async function while the bot mains? #4715
-
I have created a bot, and I need an extern service to run concurrently to the bot. 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? |
Beta Was this translation helpful? Give feedback.
Answered by
Bibo-Joshi
Mar 10, 2025
Replies: 1 comment
-
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 |
Beta Was this translation helpful? Give feedback.
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
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