Last active
August 29, 2015 14:16
-
-
Save shanechin/fb8ba0c4d47c80f7cce7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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