Skip to content

Instantly share code, notes, and snippets.

@mattyw
Created November 3, 2010 17:01
Show Gist options
  • Save mattyw/661356 to your computer and use it in GitHub Desktop.
Save mattyw/661356 to your computer and use it in GitHub Desktop.
This simple module will start three processes that just count up forever, they will each run in a separate interpreter so won't be affected by the GIL. When you stop the main process the sub processes will die (after a delay of 5 seconds). I'm trying o
import time
import sys
from multiprocessing import Process, Pipe
def test_proc(name, conn):
x = 0
while True:
#print x
x += 1
if conn.poll(10):
conn.recv()
else:
break
class ProcessManagement:
def __init__(self, name, proc, pipe):
self.name = name
self.proc = proc
self.pipe = pipe
def main():
proc_name= ['a', 'b', 'c']
procs = []
for name in proc_name:
parent_conn, child_conn = Pipe()
p = Process(target=test_proc, args=(name, child_conn))
procs.append(ProcessManagement(name, p, parent_conn))
parent_conn.send(1)
p.start()
while True:
for manager in procs:
print 'Pid % is_alive:%s' %(manager.proc.pid, manager.proc.is_alive())
manager.pipe.send(1)
time.sleep(1)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment