pythonaiohttpweb-development-servertwitch-api

How to run twitch bot and app simultaneously


if __name__ =='__main__': 
  bot.run()
  web.run_app(app, port=5000)

I am trying to run these 2 simultaneously, however, one is blocking the other. Any help would be appreciated. Thanks


Solution

  • If they are both synchronous (no async or await) then you can use

    import threading
    
    threading.Thread(target=bot.run).start()
    # or threading.Thread(target=web.run_app, args=(app,), kwargs={"port": 5000"}
    

    and then use threading.Lock for database operations (https://docs.python.org/3/library/threading.html#threading.Lock).

    If one is asynchronous, then look at this.