multithreading - How to end program running after given time in Python -


I want my Python program to run an algorithm for a certain number and then print the best results so far

What is the best way to do this?

I tried the following but it did not work (the program is running after printing):

  def printbest result (self): print (auto.best Result) sys.exit () find the best results (self, time): self.t = threading.Timer (time, self. Best print) self.t.start () while (1): # best results Search    

Unchecked code, but something like this?

  import timeline = 60 start = time.time () best_run = threshold while while time.time () - Start & lt; Range: run_start = time.time () doSomething () run_time = time.time () - if run_time & lt; Best_run: best_run = run_time    

Comments