I want to start another process, it will start, if I write to telegram bot “start”. But right after this occurring the ERROR:
2022-04-11 11:16:13,602 (__init__.py:688 Thread-1) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. Error code: 409. Description: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"
I am running ONLY one bot at the same time, already checked it. I found, that the error occurs when program trying to start a new process. Could anyone help me, please?
from time import sleep from datetime import datetime, timedelta import telebot from telebot import types from threading import Thread import multiprocessing def collecting(a): while True: print(a) sleep(3) if __name__=='__main__': bot = telebot.TeleBot(token) workers = [] def listen(): @bot.message_handler(content_types='text') def get_text(message): id = message.chat.id mes = message.text if mes=='start': bot.send_message(id, 'okey') workers.append([str(datetime.now())]) else: bot.send_message(id, mes) bot.polling() Thread(target=listen).start() while True: sleep(1) x = workers[:] for i in range(len(x)): multiprocessing.Process(target=collecting, args=(x[i],)).start() del workers[i]
UPD: Forgot to say, this error occurred only when I create exe file and run this code like exe program. This is how I create exe file:
pyinstaller --hidden-import=pkg_resources.py2_warn --onefile Program.py
Advertisement
Answer
Solved, I forgot to add this:
from multiprocessing import freeze_support
And then after if__name__=="__main__":
also need to write freeze_support()
.