from IPython.parallel import Client
rc = Client()
# create the balanced view object
lview = rc.load_balanced_view()
def process_job(filename):
# to avoid importing functions better
# define the function in a module and import it
from time import sleep
sleep(4)
open(filename, 'w').close()
return "Done " + filename
!rm out/*.dat
process_job("out/prova.dat")
filenames = ["out/%d.dat" % (i+10) for i in range(10)]
print filenames
# default returns immediately
lview.map(process_job, filenames)
# block=True, waits for jobs to complete and return results
results = lview.map(process_job, filenames, block=True)
results
# submit one job at a time
for i in range(100, 110):
lview.apply_async(process_job, "out/%d.dat" % i)