How to let a Python thread finish gracefully,time.sleep(10)