Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Is there a way to run a concurrent async function while the bot mains?#4715

AnsweredbyBibo-Joshi
Kaki-In asked this question inQ&A
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 :

importasyncioasyncdefmain():bot=TheTelegramBotIHaveCreated(TOKEN)asyncio.create_task(run_concurrent_service())bot.application().run_polling()asyncio.run(main())

I get this error:

Traceback (mostrecentcalllast):File"/home/kaki/.local/lib/python3.10/site-packages/telegram/ext/_application.py",line1112,in__runloop.run_until_complete(self.shutdown())File"/usr/lib/python3.10/asyncio/base_events.py",line625,inrun_until_completeself._check_running()File"/usr/lib/python3.10/asyncio/base_events.py",line584,in_check_runningraiseRuntimeError('This event loop is already running')RuntimeError:Thiseventloopisalreadyrunning

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 athttps://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 byKaki-In
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@Kaki-In@Bibo-Joshi

[8]ページ先頭

©2009-2025 Movatter.jp