0

我使用 zerorpc 来构建我的 rpc 程序,但我发现了一个有趣的现象,

代码

import zerorpc

c = zerorpc.Client(timeout=0.1)
c.connect("tcp://192.168.33.12:4242")

count = 0
while True:
    print(count)
    try:
        print c.hello("RPC", async=False)
    except zerorpc.exceptions.TimeoutExpired as e:
        print(e)
    count+=1

** 上面的服务器不可达,会一直打印超时信息,但是超过1000次就卡住了gevent.queue.Channel.put(),我试了很多次,1000的数字是固定的,不知道为什么?**

输出

992
timeout after 1s, when calling remote method hello
993
timeout after 1s, when calling remote method hello
994
timeout after 1s, when calling remote method hello
995
timeout after 1s, when calling remote method hello
996
timeout after 1s, when calling remote method hello
997
timeout after 1s, when calling remote method hello
998
timeout after 1s, when calling remote method hello
999
timeout after 1s, when calling remote method hello
1000
timeout after 1s, when calling remote method hello
1001



^CKeyboardInterrupt
2021-01-09T06:12:34Z
Traceback (most recent call last):
  File "hello_client.py", line 12, in <module>
    print c.hello("RPC", async=False)
  File "/usr/lib/python2.7/site-packages/zerorpc/core.py", line 283, in <lambda>
    return lambda *args, **kargs: self(method, *args, **kargs)
  File "/usr/lib/python2.7/site-packages/zerorpc/core.py", line 272, in __call__
    bufchan.emit_event(request_event)
  File "/usr/lib/python2.7/site-packages/zerorpc/channel.py", line 234, in emit_event
    self._channel.emit_event(event)
  File "/usr/lib/python2.7/site-packages/zerorpc/heartbeat.py", line 116, in emit_event
    self._channel.emit_event(event, timeout)
  File "/usr/lib/python2.7/site-packages/zerorpc/channel.py", line 154, in emit_event
    self._multiplexer.emit_event(event, timeout)
  File "/usr/lib/python2.7/site-packages/zerorpc/channel.py", line 66, in emit_event
    return self._events.emit_event(event, timeout)
  File "/usr/lib/python2.7/site-packages/zerorpc/events.py", line 360, in emit_event
    self._send(parts, timeout)
  File "/usr/lib/python2.7/site-packages/zerorpc/events.py", line 136, in __call__
    self._send_queue.put(parts, timeout=timeout)
  File "src/gevent/queue.py", line 629, in gevent._queue.Channel.put
  File "src/gevent/queue.py", line 624, in gevent._queue.Channel.put
  File "src/gevent/_waiter.py", line 151, in gevent.__waiter.Waiter.get
  File "src/gevent/_greenlet_primitives.py", line 60, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 60, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 64, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/__greenlet_primitives.pxd", line 35, in gevent.__greenlet_primitives._greenlet_switch
KeyboardInterrupt

任何帮助将不胜感激

4

0 回答 0