Multiprocessing / threading confusion

Paul Pittlerson menkomigen6 at gmail.com
Fri Sep 6 14:27:05 EDT 2013


Ok here is the fixed and shortened version of my script:

#!/usr/bin/python

from multiprocessing import Process, Queue, current_process
from threading import Thread
from time import sleep

class Worker():
    def __init__(self, Que):
        self._pid = current_process().pid        
        self.que = Que
        self.que.put('started worker %s' % self._pid)
        
        for n in range(5):
            self.que.put('%s tick %d' % (self._pid, n))
            # do some work
            sleep(0.01)
            
        self.que.put('%s has exited' % self._pid) 
        
class Debugger(Thread):
    def __init__(self, q):
        super(Debugger, self).__init__()
        self.q = q
        
    def run(self):
        while True:
            
            sleep(0.1)
            
            if not self.q.empty():
                print self.q.get()
                
            else:
                break
        #

if __name__ == '__main__':
    
    debug_q = Queue()
    debug = Debugger(debug_q)
    debug.start()
    
    for i in range(5):
        
        d = Process(target=Worker, args=(debug_q,))
        d.start()

This works great on linux, but does not run on windows (7). The behavior was: I 
opened it with double clicking and so a window appeared and disappeared (no 
text) then I opened it with IDLE and ran it there, where it worked a couple 
times. Then reopened it with IDLE and this time it did not work at all. After 
that the script did not run either through IDLE or opening directly.

What may be the reason it works on linux, but seems buggy on windows?



More information about the Python-list mailing list