mercredi 23 juin 2021

Stopping a thread after a Boolean value is set to true from another function

 stop = False
 class thread(threading.Thread):
   def run(self):
     execute_js('something.js')

 class worker(threading.Thread):
   def stop(self):
     global stop
     self.stop = True
   def start(self,stop):
      thread = thread()
      thread.start()
      if self.stop == True:
         thread.join()
     

I am trying to stop a running thread by using thread.join() . In the code snippet above, I have set global variable "stop" to false and it is set to true after a button stop is clicked from the stop function. The start function is running the thread and it does not enter the if loop with the condition stop == True. And is that a correct way of stopping a running thread after the condition is checked ?

Aucun commentaire:

Enregistrer un commentaire