Python multiprocessing Process crashes silently

后端 未结 3 1113
北荒
北荒 2021-02-14 02:08

I\'m using Python 2.7.3. I have parallelised some code using subclassed multiprocessing.Process objects. If there are no errors in the code in my subclassed Process

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-14 02:27

    This is not an answer, just an extended comment. Please run this program an tell us what output (if any) you get:

    from multiprocessing import Process, Queue
    
    class Worker(Process):
    
        def __init__(self, inputQueue, outputQueue):
    
            super(Worker, self).__init__()
    
            self.inputQueue = inputQueue
            self.outputQueue = outputQueue
    
        def run(self):
    
            for i in iter(self.inputQueue.get, 'STOP'):
    
                # (code that does stuff)
    
                1 / 0 # Dumb error
    
                # (more code that does stuff)
    
                self.outputQueue.put(result)
    
    if __name__ == '__main__':
        inq, outq = Queue(), Queue()
        inq.put(1)
        inq.put('STOP')
        w = Worker(inq, outq)
        w.start()
    

    I get:

    % test.py
    Process Worker-1:
    Traceback (most recent call last):
      File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
        self.run()
      File "/home/unutbu/pybin/test.py", line 21, in run
        1 / 0 # Dumb error
    ZeroDivisionError: integer division or modulo by zero
    

    I'm surprised (if) you get nothing.

提交回复
热议问题