May-03-2017, 08:43 PM
Ok, so after googling, the multiprocessing module itself has a version of Queue which is safe for... multiprocessing. So I made a few minor changes to use that queue instead, and also to how you're checking if there's a message in the queue (better to ask forgiveness than permission):
import time import multiprocessing import queue def cleancycle(seconds): msgqueue=multiprocessing.Queue() ctr=multiprocessing.Process(target=timeremaining,args=(seconds,msgqueue)) print('clean') print('Queue: {}'.format(queue)) print('clean on') ctr.start() time.sleep(10) msgqueue.put('stop') def timeremaining(seconds=0,msgqueue=None): print('Time: {}'.format(seconds)) print('Queue: {}'.format(queue)) while seconds != 0: print('time remaining: {}'.format(seconds)) seconds-=1 time.sleep(1) try: msg=msgqueue.get(False) if msg=='stop': print('Exit loop') break except queue.Empty: pass def main(): seconds=100 while True: cleancycle(seconds) time.sleep(120) if __name__ == '__main__': main()