Skip to content

Instantly share code, notes, and snippets.

@ajasja
Last active August 29, 2015 14:07
Show Gist options
  • Save ajasja/2bec227008d09f92cd46 to your computer and use it in GitHub Desktop.
Save ajasja/2bec227008d09f92cd46 to your computer and use it in GitHub Desktop.
$ dispynode.py -d
2014-10-14 19:11:11,141 - asyncoro - poller: IOCP
2014-10-14 19:11:11,141 - dispynode - serving 6 cpus at 194.249.230.57:51348
2014-10-14 19:11:11,141 - dispynode - tcp server at 194.249.230.57:51348
2014-10-14 19:11:27,665 - dispynode - dest_path for "compute": j:\tmp\ajasja\dispy\49e57327736a553c
2014-10-14 19:11:27,665 - dispynode - Copying file long_work.py to j:\tmp\ajasja\dispy\49e57327736a553c\long_work.py (409)
2014-10-14 19:11:27,665 - dispynode - Copied file j:\tmp\ajasja\dispy\49e57327736a553c\long_work.py, ACK
2014-10-14 19:11:27,680 - dispynode - setup "set_up" failed
2014-10-14 19:11:27,680 - dispynode - Traceback (most recent call last):
File "j:/Programs/Python/WinPython-32bit-2.7.6.3/python-2.7.6/Scripts/dispynode.py", line 615, in setup_computation
if setup():
File "<string>", line 6, in set_up
ImportError: No module named long_work
"""
Test unit with looong loading time
"""
import os
import time
import socket
initialized = False
def init(num):
global initialized
print "Start loong work: %s" % time.ctime()
time.sleep( num )
print "End looong work: %s" % time.ctime()
initialized = True
def do_work(num):
if not initialized:
init(num)
else:
print "Work done"
return (socket.gethostname(), num+15)
#!python
def compute(n):
import long_work
return long_work.do_work(n)
def set_up():
import long_work
long_work.init(0)
return 0
print set_up()
print compute(0)
if __name__ == '__main__':
import dispy, random
cluster = dispy.JobCluster(compute, setup=set_up, depends=["long_work.py"])
jobs = []
for n in range(20):
job = cluster.submit(random.randint(5,20))
job.id = n
jobs.append(job)
print dir(jobs[0])
cluster.wait()
for job in jobs:
res = job()
if res is None:
print job.stdout, job.stderr, job.exception, job.ip_addr, job.start_time, job.end_time
print ""
else:
host, n = res
print '%s executed job %s at %s with %s' % (host, job.id, job.start_time, n)
# other fields of 'job' that may be useful:
# print job.stdout, job.stderr, job.exception, job.ip_addr, job.start_time, job.end_time
cluster.stats()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment