Created
October 6, 2015 21:10
-
-
Save shamidreza/4ec62601b4bd22480cb9 to your computer and use it in GitHub Desktop.
a python script showing multiprocessing abilities of python
This file contains 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
{ | |
"metadata": { | |
"name": "multi" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "raw", | |
"metadata": {}, | |
"source": "The following script shows you how to use multiprocessing module in python. We invoke the calls to one function using different parameters in different processes." | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "import multiprocessing\n\ndef foo(num): # function to be called\n return num * 2\n\nif __name__ == '__main__':\n pool = multiprocessing.Pool()\n params = [0,2,5,8,11,16] # a list of parameters\n results = pool.map(foo, params)\n print(results)\n \n ", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "[0, 4, 10, 16, 22, 32]\n" | |
} | |
], | |
"prompt_number": 7 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment