[Fixed]-Python3 webserver communicate between threads for IRC bot

1👍

✅

The problem is, as you noticed, that you spawn a new thread/bot each time there is an upload. A possible solution would be to rewrite your code to do something like this:

event_queue = multiprocessing.Queue() # Events that will be sent to the IRC bot thread

def irc_bot_thread():
    bot = connect_to_irc()

    for event in event_queue:
        bot.handle_event(event)

threading.Thread(target=irc_bot_thread).start()

def upload_file(filename, rec_nick, pw):
    # Django stuff

    event_queue.push(<necessary data for use by the bot>)

Leave a comment