##// END OF EJS Templates
test view.map on a generator
test view.map on a generator

File last commit:

r9190:20a102a5
r10571:16ddad4f
Show More
map.py
38 lines | 832 B | text/x-python | PythonLexer
Thomas Kluyver
Update print syntax in parallel examples.
r6455 from __future__ import print_function
MinRK
move IPython.zmq.parallel to IPython.parallel
r3666 from IPython.parallel import *
MinRK
updated newparallel examples, moved into docs
r3609
client = Client()
MinRK
update a few parallel examples...
r4184 view = client.load_balanced_view()
MinRK
updated newparallel examples, moved into docs
r3609
MinRK
update API after sagedays29...
r3664 @view.remote(block=True)
MinRK
updated newparallel examples, moved into docs
r3609 def square(a):
"""return square of a number"""
return a*a
squares = map(square, range(42))
# but that blocked between each result; not exactly useful
square.block = False
arlist = map(square, range(42))
# submitted very fast
# wait for the results:
squares2 = [ r.get() for r in arlist ]
# now the more convenient @parallel decorator, which has a map method:
MinRK
update a few parallel examples...
r4184 view2 = client[:]
@view2.parallel(block=False)
MinRK
updated newparallel examples, moved into docs
r3609 def psquare(a):
"""return square of a number"""
return a*a
# this chunks the data into n-negines jobs, not 42 jobs:
ar = psquare.map(range(42))
# wait for the results to be done:
squares3 = ar.get()
Thomas Kluyver
Update print syntax in parallel examples.
r6455 print(squares == squares2, squares3==squares)
# True