Python多处理进程PID与实际PID不同

Ara*_*orn 5 python pid python-multiprocessing

这是我的代码。我正在尝试创建 n(此处为 10)个进程,只是想查看它们的 PIDS。当我打印它们并在终端中验证 PID 时,它们不一样。编辑:如果有帮助,我正在 Mac (Yosemite) 上运行它。

for proc in xrange(10):
        worker_process = Process (name="worker_process", target=worker_code, args=(proc, tree_space, self.simulator, mgr_nms))
        process_q.append(worker_process)
        worker_process.start()
        print worker_process.pid
Run Code Online (Sandbox Code Playgroud)

我的输出:

60484
60485
60486
60487
60488
60489
60490
60491
60493
60494
Run Code Online (Sandbox Code Playgroud)

终端输出(顶部):

(图片)-> http://postimg.org/image/kkiboom6l/

关于为什么会这样的任何指示?(对不起,如果我遗漏了一些如此明显的东西。)

Mar*_*cny 0

我在您的屏幕截图中看到两个 PPID(父 PID):60480 和 60481(最右侧)。

你确定你的程序没有运行两次吗?屏幕截图已被截断,但我猜如果您确实运行代码两次,您会在那里看到 20 个 Python 进程。

我已经从该屏幕截图中计算出了总共 14 个 Python 进程,而实际上最多应该有 11 个。

编辑:

实际上 60481 的 PPID 是 60480。所以看起来您正在运行该程序一次,但生成进程(使用Process())早于您在此处提供的代码。这很可能是您问题的根源。