簡體   English   中英

如何在給定時間段內執行代碼

[英]How to execute a code for a given time period

我想知道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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM