运行 dispy 文档中给出的示例代码
def compute(n):
import time, socket
time.sleep(n)
host = socket.gethostname()
return (host, n)
if name == 'main':
import dispy, random
cluster = dispy.JobCluster(compute)
jobs = []
for i in range(10):
# schedule execution of 'compute' on a node (running 'dispynode')
# with a parameter (random number in this case)
job = cluster.submit(random.randint(5,20))
job.id = i # optionally associate an ID to job (if needed later)
jobs.append(job)
# cluster.wait() # wait for all scheduled jobs to finish
for job in jobs:
host, n = job() # waits for job to finish and returns results
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.print_status()
我得到以下输出
2017-03-29 22:39:52 asyncoro - 带有 epoll I/O 通知器的 4.5.2 版
2017-03-29 22:39:52 dispy - dispy 客户端版本:4.7.3
2017-03-29 22:39:52 dispy - 端口 51347 似乎被另一个程序使用
然后什么也没有发生。如何释放 51347 端口?