helloworld.ipynb
64 lines
| 2.5 KiB
| text/plain
|
TextLexer
Brian E. Granger
|
r4634 | { | |
"nbformat": 2, | |||
Brian E. Granger
|
r4637 | "metadata": { | |
"name": "helloworld" | |||
}, | |||
Brian E. Granger
|
r4634 | "worksheets": [ | |
{ | |||
"cells": [ | |||
{ | |||
"source": "# Distributed hello world\n\nOriginally by Ken Kinder (ken at kenkinder dom com)", | |||
"cell_type": "markdown" | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"language": "python", | |||
"outputs": [], | |||
"collapsed": true, | |||
"prompt_number": 3, | |||
"input": "from IPython.parallel import Client" | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"language": "python", | |||
"outputs": [], | |||
"collapsed": true, | |||
"prompt_number": 4, | |||
"input": "rc = Client()\nview = rc.load_balanced_view()" | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"language": "python", | |||
"outputs": [], | |||
"collapsed": true, | |||
"prompt_number": 5, | |||
"input": "def sleep_and_echo(t, msg):\n import time\n time.sleep(t)\n return msg" | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"language": "python", | |||
"outputs": [], | |||
"collapsed": true, | |||
"prompt_number": 6, | |||
"input": "world = view.apply_async(sleep_and_echo, 3, 'World!')\nhello = view.apply_async(sleep_and_echo, 2, 'Hello')\n" | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"language": "python", | |||
"outputs": [ | |||
{ | |||
"output_type": "stream", | |||
"text": "Submitted tasks: ['9e533683-d54e-4588-929e-984dd3eb6dc4'] ['90395f15-723f-44df-a743-a5d88cdeb6a0']\nHello" | |||
}, | |||
{ | |||
"output_type": "stream", | |||
"text": "World!" | |||
} | |||
], | |||
"collapsed": false, | |||
"prompt_number": 7, | |||
"input": "print \"Submitted tasks:\", hello.msg_ids, world.msg_ids\nprint hello.get(), world.get()" | |||
} | |||
] | |||
} | |||
] | |||
} |