电脑不能下载python_python,ConnectionRefusedError: 由于目标计算机积极拒绝,无法连接汗血宝马...

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36import time, sys, queue

from multiprocessing.managers import BaseManager

# 创建类似的QueueManager:

class QueueManager(BaseManager):

pass

# 由于这个QueueManager只从网络上获取Queue,所以注册时只提供名字:

QueueManager.register('get_task_queue')

QueueManager.register('get_result_queue')

# 连接到服务器,也就是运行task_master.py的机器:

server_addr = '127.0.0.1'

print('Connect to server %s...' % server_addr)

# 端口和验证码注意保持与task_master.py设置的完全一致:

m = QueueManager(address=(server_addr, 5000), authkey=b'abc')

# 从网络连接:

m.connect()

# 获取Queue的对象:

task = m.get_task_queue()

result = m.get_result_queue()

# 从task队列取任务,并把结果写入result队列:

for i in range(10):

try:

n = task.get(timeout=1)

print('run task %d * %d...' % (n, n))

r = '%d * %d = %d' % (n, n, n*n)

time.sleep(1)

result.put(r)

except Queue.Empty:

print('task queue is empty.')

# 处理结束:

print('worker exit.')

if __name__ == '__main__':

pass

运行了之后报错:

1

2

3

4

5

6

7

8

9

10

11

12

13

14C:\Users\ACER\AppData\Local\Programs\Python\Python35-32\python.exe D:/somethingnew/task_worker.py

Connect to server 127.0.0.1...

Traceback (most recent call last):

File "D:/somethingnew/task_worker.py", line 18, in <module>

m.connect()

File "C:\Users\ACER\AppData\Local\Programs\Python\Python35-32\lib\multiprocessing\managers.py", line 455, in connect

conn = Client(self._address, authkey=self._authkey)

File "C:\Users\ACER\AppData\Local\Programs\Python\Python35-32\lib\multiprocessing\connection.py", line 487, in Client

c = SocketClient(address)

File "C:\Users\ACER\AppData\Local\Programs\Python\Python35-32\lib\multiprocessing\connection.py", line 614, in SocketClient

s.connect(address)

ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

Process finished with exit code 1

这个是我在廖老师的教程看到分布式进程里面照打的教程看的有点懵,然后在pycharm里面运行之后报错,我在百度谷歌之类的搜了不止一个小时了,实在不懂,小白就是这样,any solutions?求救

你的127.0.0.1的5000端口有服务吗?我估计是没有,没有自然就拒绝连接了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值