File: helloworld.py

package info (click to toggle)
ipython 0.13.1-2%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,752 kB
  • sloc: python: 69,537; makefile: 355; lisp: 272; sh: 80; objc: 37
file content (35 lines) | stat: -rw-r--r-- 596 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# <nbformat>2</nbformat>

# <markdowncell>

# # Distributed hello world
# 
# Originally by Ken Kinder (ken at kenkinder dom com)

# <codecell>
from __future__ import print_function

from IPython.parallel import Client

# <codecell>

rc = Client()
view = rc.load_balanced_view()

# <codecell>

def sleep_and_echo(t, msg):
    import time
    time.sleep(t)
    return msg

# <codecell>

world = view.apply_async(sleep_and_echo, 3, 'World!')
hello = view.apply_async(sleep_and_echo, 2, 'Hello')

# <codecell>

print("Submitted tasks:", hello.msg_ids, world.msg_ids)
print(hello.get(), world.get())