I need to launch a lot of telegram bots. I can run bots in local mode on Windows or Mac.
An error occurs when running Docker
backend1-1 | File "uvloop/loop.pyx", line 2887, in uvloop.loop.Loop.add_signal_handler
backend1-1 | ValueError: add_signal_handler() can only be called from the main thread
Code:
bot = BaseTelegramBot(bot_data=bot_data)
bot_thread = threading.Thread(target=bot.run_bot)
bot_thread.start()
class BaseTelegramBot:
def __init__(self, bot_data):
super().__init__()
self.bot = Bot(token=self.token)
self.dispatcher = Dispatcher()
def run_bot(self):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(self.start())
loop.close()
async def start(self):
await self.dispatcher.start_polling(self.bot)
Tried two options:
1)
bot = BaseTelegramBot(bot_data=bot_data)
asyncio.run(bot.start()) # для MacOS - убрать строку
bot = BaseTelegramBot(bot_data=bot_data)
with concurrent.futures.ThreadPoolExecutor() as executor: # для MacOS - добавить строки во всех api
executor.submit(bot.start)
I don’t understand why this is such a problem in Docker. HELP! How to run bots in thread mode
New contributor
Nikki Nikkonor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.