from IPython.parallel import Client
rc = Client()
# create the balanced view object
lview = rc.load_balanced_view()
rc.ids
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
!mkdir out
!rm out/*.dat
process_job("out/test.dat")
filenames = ["out/%d.dat" % (i+10) for i in range(10)]
print filenames
# default returns immediately
tasks = []
for filename in filenames:
tasks.append(lview.apply_async(process_job, filename))
print tasks[0]
print tasks[0].ready()
print tasks[0].ready()