我有一些代码,我想异步安排执行。我试过这样做:
time.sleep(3)
print("Do stuff")
但这阻止了我的脚本,而且看起来也很愚蠢。
如何在 Python 中重写此 Javascript 代码?
setTimeout(function() {
print("Do stuff")
}.bind(this), 3000);
我想出了这个:
import threading
thread = threading.Timer(3.0, do_stuff)
thread.start()
我不想使用线程。线程是愚蠢的。
如果使用龙卷风,答案是这样的:
tornado.ioloop.IOLoop.current().add_timeout(timedelta(seconds=1), do_stuff
(
无需使用线程