It seems using socket module patched by gevent lib makes PyDev test runner dysfunctional.
PyDev test runner uses xmlrpclib (which in turn uses httplib, which in turn uses socket). Running any test where socket is patched by gevent makes test runner fail with "NotImplementedError: gevent is only usable from a single thread".
Below is a "test case" and output.
In case someone knows how to handle this I would gladly hear the solution.
fromgeventimportmonkeymonkey.patch_all(socket=True,# socket=False makes PyDev test runner run ok dns=True,time=True,select=True,thread=True,os=True,ssl=True,httplib=False,aggressive=True)importgeventimportunittestdefgevent_spawn():deff(x):print"f: ",xgreens=[gevent.spawn(f,x)forxinrange(4)]gevent.joinall(greens)classTest(unittest.TestCase):deftest(self):gevent_spawn()if__name__=='__main__':gevent_spawn()
OUTPUT
pydev debugger: starting
Finding files... done.
Importing test modules ... done.
Traceback (most recent call last):
File "C:\eclipse\indigo\plugins\org.python.pydev.debug_2.3.0.2011122300\pysrc\pydev_runfiles_xml_rpc.py", line 131, in run
self.server.notifyCommands(commands)
File "c:\program files\python\2.7\Lib\xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "c:\program files\python\2.7\Lib\xmlrpclib.py", line 1575, in __request
verbose=self.__verbose
File "c:\program files\python\2.7\Lib\xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "c:\program files\python\2.7\Lib\xmlrpclib.py", line 1292, in single_request
self.send_content(h, request_body)
File "c:\program files\python\2.7\Lib\xmlrpclib.py", line 1439, in send_content
connection.endheaders(request_body)
File "c:\program files\python\2.7\Lib\httplib.py", line 951, in endheaders
self._send_output(message_body)
File "c:\program files\python\2.7\Lib\httplib.py", line 811, in _send_output
self.send(msg)
File "c:\program files\python\2.7\Lib\httplib.py", line 773, in send
self.connect()
File "c:\program files\python\2.7\Lib\httplib.py", line 754, in connect
self.timeout, self.source_address)
File "C:\python\virtualenv\envX\lib\site-packages\gevent-0.13.6-py2.7-win-amd64.egg\gevent\socket.py", line 641, in create_connection
f: sock.connect(sa)
0 File "C:\python\virtualenv\envX\lib\site-packages\gevent-0.13.6-py2.7-win-amd64.egg\gevent\socket.py", line 371, in connect
wait_readwrite(sock.fileno(), event=self._rw_event)
File "C:\python\virtualenv\envX\lib\site-packages\gevent-0.13.6-py2.7-win-amd64.egg\gevent\socket.py", line 215, in wait_readwrite
f: switch_result = get_hub().switch()
1
File "C:\python\virtualenv\envX\lib\site-packages\gevent-0.13.6-py2.7-win-amd64.egg\gevent\hub.py", line 135, in get_hub
f: 2
raise NotImplementedError('gevent is only usable from a single thread')
f: 3
NotImplementedError: gevent is only usable from a single thread
----------------------------------------------------------------------
Ran 1 test in 0.012s
OK
Traceback (most recent call last):
File "C:\eclipse\indigo\plugins\org.python.pydev.debug_2.3.0.2011122300\pysrc\pydev_runfiles_xml_rpc.py", line 131, in run
self.server.notifyCommands(commands)
File "c:\program files\python\2.7\Lib\xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "c:\program files\python\2.7\Lib\xmlrpclib.py", line 1575, in __request
verbose=self.__verbose
File "c:\program files\python\2.7\Lib\xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "c:\program files\python\2.7\Lib\xmlrpclib.py", line 1292, in single_request
self.send_content(h, request_body)
File "c:\program files\python\2.7\Lib\xmlrpclib.py", line 1439, in send_content
connection.endheaders(request_body)
File "c:\program files\python\2.7\Lib\httplib.py", line 951, in endheaders
self._send_output(message_body)
File "c:\program files\python\2.7\Lib\httplib.py", line 811, in _send_output
self.send(msg)
File "c:\program files\python\2.7\Lib\httplib.py", line 773, in send
self.connect()
File "c:\program files\python\2.7\Lib\httplib.py", line 754, in connect
self.timeout, self.source_address)
File "C:\python\virtualenv\envX\lib\site-packages\gevent-0.13.6-py2.7-win-amd64.egg\gevent\socket.py", line 641, in create_connection
sock.connect(sa)
File "C:\python\virtualenv\envX\lib\site-packages\gevent-0.13.6-py2.7-win-amd64.egg\gevent\socket.py", line 371, in connect
wait_readwrite(sock.fileno(), event=self._rw_event)
File "C:\python\virtualenv\envX\lib\site-packages\gevent-0.13.6-py2.7-win-amd64.egg\gevent\socket.py", line 215, in wait_readwrite
switch_result = get_hub().switch()
File "C:\python\virtualenv\envX\lib\site-packages\gevent-0.13.6-py2.7-win-amd64.egg\gevent\hub.py", line 135, in get_hub
raise NotImplementedError('gevent is only usable from a single thread')
NotImplementedError: gevent is only usable from a single thread
Traceback (most recent call last):
File "C:\eclipse\indigo\plugins\org.python.pydev.debug_2.3.0.2011122300\pysrc\pydev_runfiles_xml_rpc.py", line 131, in run
self.server.notifyCommands(commands)
File "c:\program files\python\2.7\Lib\xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "c:\program files\python\2.7\Lib\xmlrpclib.py", line 1575, in __request
verbose=self.__verbose
File "c:\program files\python\2.7\Lib\xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "c:\program files\python\2.7\Lib\xmlrpclib.py", line 1292, in single_request
self.send_content(h, request_body)
File "c:\program files\python\2.7\Lib\xmlrpclib.py", line 1439, in send_content
connection.endheaders(request_body)
File "c:\program files\python\2.7\Lib\httplib.py", line 951, in endheaders
self._send_output(message_body)
File "c:\program files\python\2.7\Lib\httplib.py", line 811, in _send_output
self.send(msg)
File "c:\program files\python\2.7\Lib\httplib.py", line 773, in send
self.connect()
File "c:\program files\python\2.7\Lib\httplib.py", line 754, in connect
self.timeout, self.source_address)
File "C:\python\virtualenv\envX\lib\site-packages\gevent-0.13.6-py2.7-win-amd64.egg\gevent\socket.py", line 641, in create_connection
sock.connect(sa)
File "C:\python\virtualenv\envX\lib\site-packages\gevent-0.13.6-py2.7-win-amd64.egg\gevent\socket.py", line 371, in connect
wait_readwrite(sock.fileno(), event=self._rw_event)
File "C:\python\virtualenv\envX\lib\site-packages\gevent-0.13.6-py2.7-win-amd64.egg\gevent\socket.py", line 215, in wait_readwrite
switch_result = get_hub().switch()
File "C:\python\virtualenv\envX\lib\site-packages\gevent-0.13.6-py2.7-win-amd64.egg\gevent\hub.py", line 135, in get_hub
raise NotImplementedError('gevent is only usable from a single thread')
NotImplementedError: gevent is only usable from a single thread
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi!
It seems using socket module patched by gevent lib makes PyDev test runner dysfunctional.
PyDev test runner uses xmlrpclib (which in turn uses httplib, which in turn uses socket). Running any test where socket is patched by gevent makes test runner fail with "NotImplementedError: gevent is only usable from a single thread".
Below is a "test case" and output.
In case someone knows how to handle this I would gladly hear the solution.
OUTPUT