Reputation: 487
This is my code. I am trying to create n(=10 here) processes and just trying to see their PIDS. When I print them and verify the PID in terminal, they are not the same. EDIT : I am running this on a Mac (Yosemite) if that helps.
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
My Output:
60484
60485
60486
60487
60488
60489
60490
60491
60493
60494
Terminal Output (top):
(IMAGE) -> http://postimg.org/image/kkiboom6l/
Any pointers regarding why this is ? (sorry if I am missing something so obvious.)
Upvotes: 6
Views: 8544
Reputation: 59681
I see two PPID's (parent PID's) in your screenshot: 60480 and 60481 (far right side).
Are you sure you are not running your program twice? The screenshot is cut off, but I'm guessing you would see 20 Python processes there if you are indeed running your code twice.
I am already counting 14 Python processes in total from that screenshot, where there should be at most 11.
EDIT:
Actually the PPID of 60481 is 60480. So it looks like you are running this program once, but are spawning processes (using Process()
) earlier than the code you provided here. That is most likely the source of your problem.
Upvotes: 0