how to let a python thread finish gracefully,time.sleep(10)