This works fine for me in Ubuntu:
>>> from time import sleep
>>> from multiprocessing import Process, Pipe
>>>
>>> def test_proc(name, conn):
... x = 0
... while True:
... #print x
... x += 1
... conn.poll()
...
>>> def main():
... proc_name= ['a', 'b', 'c']
... procs = [Process(target=test_proc, args=Pipe()) for p in proc_name]
... for p in procs:
... p.start()
... while True:
... print [(p.is_alive(), 'Pid %s' %(p.pid)) for p in procs]
... sleep(1)
...
>>> main()
[(True, 'Pid 423'), (True, 'Pid 424'), (True, 'Pid 425')]
[(True, 'Pid 423'), (True, 'Pid 424'), (True, 'Pid 425')]
[(True, 'Pid 423'), (True, 'Pid 424'), (True, 'Pid 425')]
[(True, 'Pid 423'), (True, 'Pid 424'), (True, 'Pid 425')]
...
Are you using Windows, maybe? There are programming guidelines that relate to using multiprocessing with Windows. In particular, you need to provide an entry point by using if __name__ == '__main__':.
Later: actually, there is something I don't get. In your original code, you expected to kill the parent of the threads and have the threads keep running. How were you killing the parent -- main() in my code? And if the threads were performing no I/O, how did you know that the threads were still alive?
And later still: When I run the threads, I get this:
>>> main()
[(True, 'Pid 940'), (True, 'Pid 941'), (True, 'Pid 942')]
[(True, 'Pid 940'), (True, 'Pid 941'), (True, 'Pid 942')]
[(True, 'Pid 940'), (True, 'Pid 941'), (True, 'Pid 942')]
[(True, 'Pid 940'), (True, 'Pid 941'), (True, 'Pid 942')]
[(True, 'Pid 940'), (True, 'Pid 941'), (True, 'Pid 942')]
and this:
PID TTY TIME CMD
911 pts/6 00:00:00 python
940 pts/6 00:00:29 python
941 pts/6 00:00:29 python
942 pts/6 00:00:37 python
944 pts/5 00:00:00 ps
And when I kill the main thread in python (Ctrl-C), I get this:
PID TTY TIME CMD
911 pts/6 00:00:00 python
940 pts/6 00:00:42 python <defunct>
941 pts/6 00:00:50 python <defunct>
942 pts/6 00:00:51 python <defunct>
946 pts/5 00:00:00 ps
Is this unexpected or undesirable?