KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to use a queue with the multiprocessing library in Python. After executing the code below (the print statements work), but the processes do not quit after I call join on the Queue and there are still alive. How can I terminate the remaining processes? Thanks! def MultiprocessTest(self): print "Starting multiprocess." print "Number of CPUs",multiprocessing.cpu_count() num_procs = 4 def do_work(message): print "work",message ,"completed" def worker(): while True: item = q.get() do_work(item) q.task_done() q = multiprocessing.JoinableQueue() for i in range(num_procs): p = multiprocessing.Process(target=worker) p.daemon = True p.start() source = ['hi','there','how','are','you','doing'] for item in source: q.put(item) print "q close" q.join() #q.close() print "Finished everything...." print "num active children:",multiprocessing.active_children()
Tags (comma-separated)
Save Edits
Cancel