import multiprocessing as mp . from multiprocessing import Process, Queue, Manager . from threading import Thread . from subprocess import Popen, PIPE, STDOUT . count = 0 def loop1(): while True: for i in range(0, 100): count = count + 1 . time.sleep(2) if count == 100: count = 0 def worker(filename): proc = Popen(["{0}".format(filename)], stdout=PIPE, stderr=STDOUT, shell=True) (proc.communicate()[0]) def loop2(): while True: for i in ["a.py", "b.py"]: if count == 50: # run some executable in background and do not wait for it . p = Process(target=worker, args=(i)) . a.sleep(2) if __name__ == '__main__': T1 = Thread(target=loop1, args=()) T2 = Thread(target=loop2, args=()) T1.start() . T2.start() . #T1.join() . #T2.join() 1) how should I start two methods in parallel ? I need to check the variable status of method1 in method2? T1.start() and T2.start() starting one by one not at the same time.
2) the tasks of loop2 has to run again after 50 seconds.