我正在努力设置 dispy 和 SSL。以下是我设置的步骤:
要创建证书,我使用了命令:
openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout private.key -out private.crt -days 3650
然后我合并了两个文件:
cat private.crt private.key > private.pem
在我的特殊情况下,我需要使用所有:调度程序(dispyscheduler)、节点(dispynode)和集群(SharedJobCluster)。
这是我提交的工作:
# canonical.py
# function 'compute' is distributed and executed with arguments
# supplied with 'cluster.submit' below
def compute(n):
import time, socket
time.sleep(n)
host = socket.gethostname()
return (host, n)
if __name__ == '__main__':
# executed on client only; variables created below, including modules imported,
# are not available in job computations
import dispy, random
# distribute 'compute' to nodes; in this case, 'compute' does not have
# any dependencies to run on nodes
cluster = dispy.SharedJobCluster(compute,
port=0,
certfile='C:\\project\\private.pem')
# run 'compute' with 20 random numbers on available CPUs
jobs = []
for i in range(5):
job = cluster.submit(random.randint(5, 5))
job.id = i # associate an ID to identify jobs (if needed later)
jobs.append(job)
# cluster.wait() # waits until all jobs 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:
# job.stdout, job.stderr, job.exception, job.ip_addr, job.end_time
cluster.print_status() # shows which nodes executed how many jobs etc.
如果我不使用 SSL 连接,尽管使用了平台,它仍能成功工作。Linux 上的调度程序和 Windows 上的节点,反之亦然。任何组合都很好。但是当我尝试使用 SSL 时问题就来了。
以下是我用来运行测试作业的命令:
在 Linux 上
dispynode.py -d --certfile=/home/dismine/project/private.pem --clean
在 Windows 上
python "C:\Program Files\Python3\Lib\site-packages\dispy\dispyscheduler.py" -d --ip_addr 127.0.0.1 --ip_addr 192.168.0.103 --node_certfile C:\project\private.pem --cluster_certfile C:\project\private.pem
python canonical.py
由于某些原因,这样的配置 - Windows 和 Unix 之间的连接不起作用。我经常看到这样的错误:
1.
Reading standard input disabled, as multiprocessing does not seem to workwith re
ading input under Windows
2018-01-03 12:50:08 dispynode - dispynode version: 4.8.3, PID: 3288
2018-01-03 12:50:08 pycos - version 4.6.5 with IOCP I/O notifier
2018-01-03 12:50:08 dispynode - "Роман-ПК" serving 2 cpus
2018-01-03 12:50:08 dispynode - TCP server at 192.168.0.101:51348
2018-01-03 12:50:08 pycos - uncaught exception in !tcp_req/36277304:
Traceback (most recent call last):
File "C:\Program Files\Python3\lib\site-packages\pycos\__init__.py", line 3730, in _schedule
retval = task._generator.throw(*exc)
File "C:\Program Files\Python3\Lib\site-packages\dispy\dispynode.py", line 988, in tcp_req
msg = yield conn.recv_msg()
File "C:\Program Files\Python3\lib\site-packages\pycos\__init__.py", line 3732, in _schedule
retval = task._generator.send(task._value)
File "C:\Program Files\Python3\lib\site-packages\pycos\__init__.py", line 882,
in _async_recv_msg
data = yield self.recvall(n)
File "C:\Program Files\Python3\lib\site-packages\pycos\__init__.py", line 1438, in _iocp_recvall
self._read_result = win32file.AllocateReadBuffer(bufsize)
MemoryError
2.
Reading standard input disabled, as multiprocessing does not seem to workwith re
ading input under Windows
2018-01-03 12:54:12 dispynode - dispynode version: 4.8.3, PID: 3284
2018-01-03 12:54:12 pycos - version 4.6.5 with IOCP I/O notifier
2018-01-03 12:54:12 dispynode - "Роман-ПК" serving 2 cpus
2018-01-03 12:54:12 dispynode - TCP server at 192.168.0.101:51348
2018-01-03 12:54:13 pycos - uncaught exception in !tcp_req/36342840:
Traceback (most recent call last):
File "C:\Program Files\Python3\lib\site-packages\pycos\__init__.py", line 3730, in _schedule
retval = task._generator.throw(*exc)
File "C:\Program Files\Python3\Lib\site-packages\dispy\dispynode.py", line 988, in tcp_req
msg = yield conn.recv_msg()
File "C:\Program Files\Python3\lib\site-packages\pycos\__init__.py", line 3732, in _schedule
retval = task._generator.send(task._value)
File "C:\Program Files\Python3\lib\site-packages\pycos\__init__.py", line 882,
in _async_recv_msg
data = yield self.recvall(n)
File "C:\Program Files\Python3\lib\site-packages\pycos\__init__.py", line 1438, in _iocp_recvall
self._read_result = win32file.AllocateReadBuffer(bufsize)
OverflowError: Python int too large to convert to C long
3.
2018-01-03 12:59:54 dispyscheduler - dispyscheduler version 4.8.3
2018-01-03 12:59:54 pycos - version 4.6.5 with epoll I/O notifier
Enter "quit" or "exit" to terminate scheduler, anything else to get status: 2018-01-03 12:59:54 dispyscheduler - Scheduler at 192.168.0.103:51349
2018-01-03 12:59:54 dispyscheduler - TCP server at 127.0.1.1:51347
2018-01-03 12:59:54 dispyscheduler - TCP server at 192.168.0.103:51347
2018-01-03 12:59:54 dispyscheduler - Scheduler at 127.0.1.1:51349
2018-01-03 12:59:54 pycos - uncaught exception in !tcp_req/139968956623560:
Traceback (most recent call last):
File "/home/dismine/project/env/lib/python3.5/site-packages/pycos/__init__.py", line 3730, in _schedule
retval = task._generator.throw(*exc)
File "/home/dismine/project/env/bin/dispyscheduler.py", line 368, in tcp_req
msg = yield conn.recv_msg()
File "/home/dismine/project/env/lib/python3.5/site-packages/pycos/__init__.py", line 3730, in _schedule
retval = task._generator.throw(*exc)
File "/home/dismine/project/env/lib/python3.5/site-packages/pycos/__init__.py", line 868, in _async_recv_msg
data = yield self.recvall(n)
File "/home/dismine/project/env/lib/python3.5/site-packages/pycos/__init__.py", line 461, in _recvall
recvd = self._rsock.recv_into(view, len(view), *args)
File "/usr/lib/python3.5/ssl.py", line 929, in recv_into
return self.read(nbytes, buffer)
File "/usr/lib/python3.5/ssl.py", line 791, in read
return self._sslobj.read(len, buffer)
File "/usr/lib/python3.5/ssl.py", line 575, in read
v = self._sslobj.read(len, buffer)
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1977)
不幸的是,我的技能不足以理解 dispy 或我的设置有什么问题。为什么在仅使用 Unix 系统或仅 Windows 系统的情况下它可以工作,但不能一起使用。
我还在GitHub 上提交了问题。