Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道 python 2.7 中是否有一种方法可以在给定的时间内运行代码,比如 3600 秒。时间可以从一次执行到另一次执行不同。欢迎任何想法,因为我遇到了这个问题。
允许出于任何原因中断计算:
def compute_something(stopped): while not stopped: # continue computations stopped = [] threading.Timer(3600, stopped.append, args=[True]).start() compute_something(stopped)