Reputation: 109
I want to know if there is a way in python 2.7 to run code for just for a given time, like 3600 seconds. The time can variate from one execution to an other. Any ideas are welcome since I am stuck with this issue.
Upvotes: 0
Views: 1146
Reputation: 414089
To allow to interrupt the computations for any reason:
def compute_something(stopped):
while not stopped:
# continue computations
stopped = []
threading.Timer(3600, stopped.append, args=[True]).start()
compute_something(stopped)
Upvotes: 1