Closed Scratchcat1 closed 7 years ago
Telegram does not allow simultaneous getUpdates
of the same token by two processes. So I guess your situation is "expected" :smile:
I see, that would explain it Thanks
@nickoala Hi. I can't find anything that solves this problem. I have the same problem with Django, PostgresSQL Database.
How can I use multiprocessing and avoid this error? Thanks
@milutinke-kortechs The way I solved it was to create another thread/process dedicated to interacting with send/recv. Messages would be forwarded on to other workers and messages to be sent would be put back on an output queue for the bot thread to send.
Just create the send/recv worker on a different thread and connect it to the rest of the application using two queues (Input and output). If you need to send a response to a particular part of the program you may need to setup some sort of routing with multiple queues.
@Scratchcat1 Hi, i am facing the same issue at the moment. May i know how you create a send and receive worker? Thank you!
@ongyiren
I created a dedicated thread with two queues, outbox
and inbox
. The thread simply keeps checking if messages have been sent to the bot and puts any it finds into the inbox
queue to be processed by the rest of the application. It then sends any messages in the outbox
queue (placed there by other threads).
I would recommend using dedicated queues for each consumer thread if you have multiple and mapping each chat to a specific inbox
queue so that any conversation will be processed in the right order.
It seems that if two processes log on using the same bot token after a short period one will crash with an SSL error. Steps to reproduce: Launching two instance of the python interpreter or two processes via multiprocessing and then creating two bot objects which then check for issues causes the one process to crash. This may not be instantanious , however sending a message to the bots which then send a response back to the chat causes one of the bots to crash with an SSL Error. Passing a bot object to another process causes the same issue. If the second bot doesn't send a message the error does not occur.