Skip to content

Instantly share code, notes, and snippets.

@shanechin
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save shanechin/fb8ba0c4d47c80f7cce7 to your computer and use it in GitHub Desktop.

Select an option

Save shanechin/fb8ba0c4d47c80f7cce7 to your computer and use it in GitHub Desktop.
import multiprocessing as mp
import os
import time, random
def f(x):
b = x*x
time.sleep(random.choice([5,8,10,14,20]))
print "{0} procces id {1} with parent {2} doing {3}".format(mp.current_process(), os.getpid(), os.getppid(), x)
return b
if __name__ == '__main__':
p = mp.Pool(2)
print(p.map(f, [1,2,3,4,5,6,82,819,1000]))
# Will try to extend this so that we can do start an interactive debugging session on
# any of the sub processes
# If the parent process dies, the child processes will still continue, but will be unable to
# send messages back to the parent which has died
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment