繁体   English   中英

在Python中经过一定时间后终止函数调用

[英]Terminate function call after a certain amount of time has elapsed in Python

我有一个不会自行终止的Python算法。 我正在对其进行一些性能分析,并希望使用一堆不同的设置在指定的时间内运行它,在该时间过去后终止它并开始下一次运行。 如何在Python中执行此操作?

for c in configs:
  # what do I wrap this with do terminate it after a 
  # set amount of time and go to next loop iteration?
  runalgorithm(config)  
start = time.time()
endt = start + 30
while True:
    now = time.time()
    if now > endt:
        return
    else:
        print end - start

在您的for循环中尝试类似的事情!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM