helloworld.py
34 lines
| 556 B
| text/x-python
|
PythonLexer
Brian E. Granger
|
r4581 | # <nbformat>2</nbformat> | ||
# <markdowncell> | ||||
# # Distributed hello world | ||||
# | ||||
# Originally by Ken Kinder (ken at kenkinder dom com) | ||||
# <codecell> | ||||
MinRK
|
r3666 | from IPython.parallel import Client | ||
MinRK
|
r3664 | |||
Brian E. Granger
|
r4581 | # <codecell> | ||
MinRK
|
r3666 | rc = Client() | ||
Brian E. Granger
|
r4581 | view = rc.load_balanced_view() | ||
# <codecell> | ||||
MinRK
|
r3664 | |||
def sleep_and_echo(t, msg): | ||||
import time | ||||
time.sleep(t) | ||||
return msg | ||||
Brian E. Granger
|
r4581 | |||
# <codecell> | ||||
MinRK
|
r3664 | |||
world = view.apply_async(sleep_and_echo, 3, 'World!') | ||||
hello = view.apply_async(sleep_and_echo, 2, 'Hello') | ||||
Brian E. Granger
|
r4581 | |||
# <codecell> | ||||
MinRK
|
r3664 | print "Submitted tasks:", hello.msg_ids, world.msg_ids | ||
print hello.get(), world.get() | ||||
Brian E. Granger
|
r4581 | |||