Alternative to signals in threads

woooee at woooee at
Wed Mar 8 21:25:46 EST 2017

Use multiprocessing since you want to do multiple things at once  If I understand you correctly, once the string is found you would terminate the process, so you would have to signal the calling portion of the code using a Manager dictionary or list..  I am not that knowledgeable about multiprocessing, so this is probably the long way around the barn.
import time
from multiprocessing import Process, Manager

def test_f(test_d):
   while True:
      ctr += 1
      print "test_f", test_d["QUIT"], ctr
      if ctr > 5:
if __name__ == '__main__':
   ## define the dictionary to be used to communicate
   manager = Manager()
   test_d = manager.dict()
   test_d["QUIT"] = False

   ## start the process
   p = Process(target=test_f, args=(test_d,))
   ## check the dictionary every half-second
   while not test_d["QUIT"]:

More information about the Python-list mailing list