运行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端口?
答案 0 :(得分:1)
如果你在Linux下,请运行sudo netstat -tuanp | grep 51347
并注意使用该端口的pid。
然后执行ps ax | grep <pid>
以检查该pid运行的服务/程序。
然后执行kill <pid>
以使用该端口终止进程。
请在杀死之前检查哪个进程正在使用该端口,以防它不应该被杀死。