Skip to content

Instantly share code, notes, and snippets.

@Excedrin
Created August 27, 2012 08:24
Show Gist options
  • Save Excedrin/3486672 to your computer and use it in GitHub Desktop.
Save Excedrin/3486672 to your computer and use it in GitHub Desktop.
2007 python multiprocessing
import os
def evalexit(code):
eval(code)
raise SystemExit
def forkexpr(s):
code = compile(s, "<string>", "eval")
os.fork() or evalexit(code)
def forkstmt(s):
code = compile(s, "<string>", "exec")
os.fork() or evalexit(code)
if __name__ == "__main__":
import time
forkstmt("for x in xrange(10): print 'child:', str(x); time.sleep(0.02)")
for x in xrange(10):
print 'parent:', x
time.sleep(0.03)
os.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment