0

I have exhausted searching the web for this task --> Properly terminate flask web app running in a thread

I have even written a smaller version of my original code but cant seem to terminate flask thread,

when I have this code, all threads start then gracefully exit:

def thrdCode1(arg):
    for i in range(arg):
        print("running")
        sleep(1)

if __name__ == "__main__":
    ngrokSetup()
    thrdH = Thread(target=thrdCode1, args=(2,))
    thrdH.deman = True
    thrdH.start()
    print("1---")
    thrdH.join()
    print("thread finished...exiting")

However when thread is with flask app.run, my thread starts but it never exits I even tried exit(-1)

def thrdCode2(arg):
    app.secret_key = 'my Top Secret'
    app.run(use_reloader=False)

if __name__ == "__main__":
    ngrokSetup()
    thrdH = Thread(target=thrdCode1, args=(2,))
    thrdH.deman = True
    thrdH.start()
    print("1---")
    thrdH.join()
    print("thread finished...exiting")

I even tried exit(-1) at end

Ghost
  • 549
  • 8
  • 29

1 Answers1

0

Ok I was able to fix this issue by sending a shutdown req. to flask

Ghost
  • 549
  • 8
  • 29