Skip to content

Instantly share code, notes, and snippets.

@shamidreza
Created October 6, 2015 21:10
Show Gist options
  • Save shamidreza/4ec62601b4bd22480cb9 to your computer and use it in GitHub Desktop.
Save shamidreza/4ec62601b4bd22480cb9 to your computer and use it in GitHub Desktop.
a python script showing multiprocessing abilities of python
Display the source blob
Display the rendered blob
Raw
{
"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