多处理池没有捕获KeyboardInterrupt

时间:2013-10-30 20:48:54

标签: python multiprocessing pool

我对multiprocessing.Pool功能有点困惑。我尝试使用它,并有兴趣捕获KeyboardInterrupt。代码有点像这样:

try:
    pool = multiprocessing.Pool(max_processes, _init_proc, [arg1, arg2])
    pool.apply(_generateTargetList)
except (KeyboardInterrupt, Exception) as err:
    logger.error("Failure while generating:'%s'", err)
    if pool:
        pool.terminate()
        pool.join()

进程按预期工作,但捕获KeyboardInterrupt不起作用。它只打印以下内容,同时生成procs和procs和procs ..

^CProcess PoolWorker-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
Process PoolWorker-9:
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 113, in worker
    self.run()
  File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 102, in worker
    result = (True, func(*args, **kwds))
  File "targets.py", line 307, in _generateTargetList
    task = get()
  File "/usr/lib/python2.7/multiprocessing/queues.py", line 374, in get
    start, end = _adjustSize(start, end)
  File "targets.py", line 258, in _adjustSize
    pretargets_w[1])
  File "targets.py", line 133, in __append
    f.flush()
KeyboardInterrupt
    racquire()
KeyboardInterrupt
Process PoolWorker-10:
Process PoolWorker-3:
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
Process PoolWorker-4:
Traceback (most recent call last):
Process PoolWorker-7:
Process PoolWorker-2:
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
Traceback (most recent call last):
Traceback (most recent call last):

有没有人知道代码有什么问题?

0 个答案:

没有答案