|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #gevent使用-猴子补丁问题
- import time
- import gevent
- #解决猴子补丁问题,使用gevent都会有如下操作
- from gevent import monkey
- monkey.patch_all() #因为gevent模块有自己的sleep,对time模块的slepp不感知。这一步用猴子来偷换gevent模块的
- def a():
- for i in range(4):
- print('A'+str(i))
- time.sleep(0.1)
- def b():
- for i in range(4):
- print('B'+str(i))
- time.sleep(0.1)
- def c():
- for i in range(4):
- print('C'+str(i))
- time.sleep(0.1)
- if __name__ == '__main__':
- ga = gevent.spawn(a)
- gb = gevent.spawn(b)
- gc = gevent.spawn(c)
- ga.join() #堵塞主进程
- gb.join()
- gc.join()
- print('------------------')
复制代码
我看出错是提前给猴子打补丁,错误提示如下
- E:/python_pycharm/进阶学习/xiecheng 3.py:5: MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors, including RecursionError on Python 3.6. It may also silently lead to incorrect behaviour on Python 3.7. Please monkey-patch earlier. See https://github.com/gevent/gevent/issues/1016. Modules that had direct imports (NOT patched): ['_shaded_thriftpy.transport._ssl (D:\\办公\\pycharm\\PyCharm Community Edition 2020.1.1\\plugins\\python-ce\\helpers\\third_party\\thriftpy\\_shaded_thriftpy\\transport\\_ssl.py)'].
- monkey.patch_all() #因为gevent模块有自己的sleep,对time模块的slepp不感知。这一步用猴子来偷换gevent模块的
- A0
- B0
- C0
- A1
- B1
- C1
- A2
- B2
- C2
- A3
- B3
- C3
- ------------------
- Traceback (most recent call last):
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_code_executor.py", line 112, in add_exec
- self.finish_exec(more)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_console_utils.py", line 210, in finish_exec
- return server.notifyFinished(more)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_comm\pydev_transport.py", line 226, in _req
- return super(TSyncClient, self)._req(_api, *args, **kwargs)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\thrift.py", line 160, in _req
- return self._recv(_api)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\thrift.py", line 172, in _recv
- fname, mtype, rseqid = self._iprot.read_message_begin()
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\protocol\binary.py", line 372, in read_message_begin
- self.trans, strict=self.strict_read)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\protocol\binary.py", line 164, in read_message_begin
- sz = unpack_i32(inbuf.read(4))
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\transport\__init__.py", line 32, in read
- return readall(self._read, sz)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\transport\__init__.py", line 14, in readall
- chunk = read_fn(sz - have)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_comm\pydev_transport.py", line 160, in _read
- return self._reader.read_response(sz)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_comm\pydev_transport.py", line 33, in read_response
- return self._response_pipe.read(sz)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_comm\pydev_io.py", line 40, in read
- self.bytes_produced.wait()
- File "D:\python3.7\Lib\threading.py", line 296, in wait
- waiter.acquire()
- File "D:\python3.7\lib\site-packages\gevent\thread.py", line 118, in acquire
- acquired = BoundedSemaphore.acquire(self, blocking, timeout)
- File "src\\gevent\\_semaphore.py", line 143, in gevent._gevent_c_semaphore.Semaphore.acquire
- File "src\\gevent\\_semaphore.py", line 178, in gevent._gevent_c_semaphore.Semaphore.acquire
- File "src\\gevent\\_abstract_linkable.py", line 381, in gevent._gevent_c_abstract_linkable.AbstractLinkable._wait
- File "src\\gevent\\_abstract_linkable.py", line 346, in gevent._gevent_c_abstract_linkable.AbstractLinkable._wait_core
- File "src\\gevent\\_abstract_linkable.py", line 348, in gevent._gevent_c_abstract_linkable.AbstractLinkable._wait_core
- File "src\\gevent\\_abstract_linkable.py", line 303, in gevent._gevent_c_abstract_linkable.AbstractLinkable._AbstractLinkable__wait_to_be_notified
- File "src\\gevent\\_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
- File "src\\gevent\\_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
- File "src\\gevent\\_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
- File "src\\gevent\\_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch
- gevent.exceptions.LoopExit: This operation would block forever
- Hub: <Hub '' at 0x1eb8b29a328 backend=default ptr=<cdata 'struct uv_loop_s *' 0x00007FFA5BC8BFA0> default pending=0 ref=0 thread_ident=0x5b50>
- Handles:
- [HandleState(handle=<cdata 'struct uv_handle_s *' 0x000001EB8A971A68>, type=b'check', watcher=<gevent.libuv.loop.loop at 0x1eb8af7a2b0 backend=default ptr=<cdata 'struct uv_loop_s *' 0x00007FFA5BC8BFA0> default pending=0 ref=0>, ref=0, active=1, closing=0),
- HandleState(handle=<cdata 'struct uv_handle_s *' 0x000001EB8A96D458>, type=b'timer', watcher=<gevent.libuv.loop.loop at 0x1eb8af7a2b0 backend=default ptr=<cdata 'struct uv_loop_s *' 0x00007FFA5BC8BFA0> default pending=0 ref=0>, ref=0, active=1, closing=0),
- HandleState(handle=<cdata 'struct uv_handle_s *' 0x000001EB8A971B18>, type=b'prepare', watcher=<gevent.libuv.loop.loop at 0x1eb8af7a2b0 backend=default ptr=<cdata 'struct uv_loop_s *' 0x00007FFA5BC8BFA0> default pending=0 ref=0>, ref=0, active=1, closing=0),
- HandleState(handle=<cdata 'struct uv_handle_s *' 0x000001EB8A9726C8>, type=b'check', watcher=<gevent.libuv.loop.loop at 0x1eb8af7a2b0 backend=default ptr=<cdata 'struct uv_loop_s *' 0x00007FFA5BC8BFA0> default pending=0 ref=0>, ref=1, active=0, closing=0)]
- Traceback (most recent call last):
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_comm\pydev_server.py", line 34, in handle
- self.processor.process(iprot, oprot)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\thrift.py", line 257, in process
- api, seqid, result, call = self.process_in(iprot)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\thrift.py", line 212, in process_in
- api, type, seqid = iprot.read_message_begin()
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\protocol\binary.py", line 372, in read_message_begin
- self.trans, strict=self.strict_read)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\protocol\binary.py", line 164, in read_message_begin
- sz = unpack_i32(inbuf.read(4))
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\transport\__init__.py", line 32, in read
- return readall(self._read, sz)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\transport\__init__.py", line 14, in readall
- chunk = read_fn(sz - have)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\transport\buffered\__init__.py", line 39, in _read
- self._rbuf = BytesIO(self._trans.read(max(sz, self._buf_size)))
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_comm\pydev_transport.py", line 215, in read
- return self._read_fn(sz)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_comm\pydev_transport.py", line 27, in read_request
- return self._request_pipe.read(sz)
- File "D:\办公\pycharm\PyCharm Community Edition 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_comm\pydev_io.py", line 40, in read
- self.bytes_produced.wait()
- File "D:\python3.7\Lib\threading.py", line 296, in wait
- waiter.acquire()
- File "D:\python3.7\lib\site-packages\gevent\thread.py", line 118, in acquire
- acquired = BoundedSemaphore.acquire(self, blocking, timeout)
- File "src\\gevent\\_semaphore.py", line 143, in gevent._gevent_c_semaphore.Semaphore.acquire
- File "src\\gevent\\_semaphore.py", line 178, in gevent._gevent_c_semaphore.Semaphore.acquire
- File "src\\gevent\\_abstract_linkable.py", line 381, in gevent._gevent_c_abstract_linkable.AbstractLinkable._wait
- File "src\\gevent\\_abstract_linkable.py", line 346, in gevent._gevent_c_abstract_linkable.AbstractLinkable._wait_core
- File "src\\gevent\\_abstract_linkable.py", line 348, in gevent._gevent_c_abstract_linkable.AbstractLinkable._wait_core
- File "src\\gevent\\_abstract_linkable.py", line 303, in gevent._gevent_c_abstract_linkable.AbstractLinkable._AbstractLinkable__wait_to_be_notified
- File "src\\gevent\\_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
- File "src\\gevent\\_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
- File "src\\gevent\\_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
- File "src\\gevent\\_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch
- gevent.exceptions.LoopExit: This operation would block forever
- Hub: <Hub '' at 0x1eb8b29a608 backend=default ptr=<cdata 'struct uv_loop_s *' 0x000001EB8B1CFCE0> pending=0 ref=0 thread_ident=0x4c34>
- Handles:
- [HandleState(handle=<cdata 'struct uv_handle_s *' 0x000001EB8A972148>, type=b'check', watcher=<gevent.libuv.loop.loop at 0x1eb8b2aa240 backend=default ptr=<cdata 'struct uv_loop_s *' 0x000001EB8B1CFCE0> pending=0 ref=0>, ref=0, active=1, closing=0),
- HandleState(handle=<cdata 'struct uv_handle_s *' 0x000001EB8A96D5F8>, type=b'timer', watcher=<gevent.libuv.loop.loop at 0x1eb8b2aa240 backend=default ptr=<cdata 'struct uv_loop_s *' 0x000001EB8B1CFCE0> pending=0 ref=0>, ref=0, active=1, closing=0),
- HandleState(handle=<cdata 'struct uv_handle_s *' 0x000001EB8A972098>, type=b'prepare', watcher=<gevent.libuv.loop.loop at 0x1eb8b2aa240 backend=default ptr=<cdata 'struct uv_loop_s *' 0x000001EB8B1CFCE0> pending=0 ref=0>, ref=0, active=1, closing=0),
- HandleState(handle=<cdata 'struct uv_handle_s *' 0x000001EB8A971858>, type=b'check', watcher=<gevent.libuv.loop.loop at 0x1eb8b2aa240 backend=default ptr=<cdata 'struct uv_loop_s *' 0x000001EB8B1CFCE0> pending=0 ref=0>, ref=1, active=0, closing=0)]
复制代码
没看懂 请大佬指教
|
|