Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python thread running twice when called once in main

if __name__ == '__main__':

    t = threading.Thread(target = authtarget)
    t.daemon = True
    t.start()
    print 'running thread'
    app.run(debug=True)

This main is in our server, where app.run will start the server and will be able to handle requests. The thread we are making is a timer that checks a certain if statement every 5 seconds. However, t.start() will create two threads instead of only one. We've tried changing t.start() to t.run() however when we do that we never get to app.run, which we need to run the server.

def authtarget():
    sp  = Spotify()
    db = Database()
    resultList = []
    while True:
        time.sleep(5)
        sp.timer(204) 

timer() is a function that we need called every 5 seconds. However, with the code that we have currently, timer gets called twice instead of once every 5 seconds

like image 809
Bob Marley and Me Avatar asked Apr 26 '17 20:04

Bob Marley and Me


1 Answers

Thanks guys, I just changed app.run(debug=True) to app.run(debug=False) so that it didn't run twice

like image 122
Bob Marley and Me Avatar answered Nov 17 '22 23:11

Bob Marley and Me