【问题标题】:Python multiprocess does not work or throw exceptionPython多进程不起作用或抛出异常
【发布时间】:2015-04-01 05:38:00
【问题描述】:

我有一个类,在构造函数中我正在创建 Process 类的对象,如下所示

self.child = multiprocessing.Process(target = self.load_paths,args = (self.paths,self.queue,))
self.child.daemon = True

在一个单独的函数中,我尝试像这样启动进程

def start_child(self):
    self.child.start()
    print 'child started'

现在每当我第 3 次或第 n+2 次调用函数 start_child() 时,子进程都会启动,但永远不会打印消息并且不会返回调用。

编辑:启动新子进程的进程也是由其他进程启动的子进程。

这不会返回任何异常,并且在 windows(python 2.7.8) 中完全按照预期工作。 问题出现在带有 python 2.7.6 的 Ubuntu 中

如果任务管理器没有在窗口中显示此代码的任何异常,我该如何缓解它?

【问题讨论】:

  • 您所说的哪条消息没有打印出来? print 'child started'?
  • 是的打印'孩子开始'
  • 通过“启动新子进程的进程也是其他进程启动的子进程”,你的意思是“start_child”,也是由其他进程启动的吗?
  • 是的,我就是这个意思。

标签: python python-2.7 multiprocessing python-multiprocessing


【解决方案1】:

我通过从multiprocessing.Process 继承目标类并覆盖运行函数来解决它。

【讨论】:

    猜你喜欢
    • 2013-09-25
    • 1970-01-01
    • 1970-01-01
    • 2019-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-07
    • 1970-01-01
    相关资源
    最近更新 更多