Commit 554ed446 authored by Denis Bilenko's avatar Denis Bilenko

hub: do not save/restore exc info

greenlet does it since 0.3.2 and does it better (stack trace is also restored)

- gevent._util.set_exc_info is removed
- update greentest/test__all__.py
- increase number of tries in debug mode
parent ffaa2474
...@@ -2,31 +2,8 @@ from python cimport * ...@@ -2,31 +2,8 @@ from python cimport *
# Work around lack of absolute_import in Cython. # Work around lack of absolute_import in Cython.
os = __import__('os', level=0) os = __import__('os', level=0)
__all__ = ['set_exc_info']
def set_exc_info(object type, object value):
cdef PyThreadState* tstate = PyThreadState_GET()
Py_XDECREF(tstate.exc_type)
Py_XDECREF(tstate.exc_value)
Py_XDECREF(tstate.exc_traceback)
if type is None:
tstate.exc_type = NULL
else:
Py_INCREF(<PyObjectPtr>type)
tstate.exc_type = <PyObjectPtr>type
if value is None:
tstate.exc_value = NULL
else:
Py_INCREF(<PyObjectPtr>value)
tstate.exc_value = <PyObjectPtr>value
tstate.exc_traceback = NULL
# We implement __del__s in Cython so that they are safe against signals # We implement __del__s in Cython so that they are safe against signals
def SocketAdapter__del__(self, close=os.close): def SocketAdapter__del__(self, close=os.close):
fileno = self._fileno fileno = self._fileno
if fileno is not None: if fileno is not None:
......
...@@ -4,13 +4,15 @@ from __future__ import absolute_import ...@@ -4,13 +4,15 @@ from __future__ import absolute_import
import sys import sys
import os import os
import traceback import traceback
try:
from gevent._util import set_exc_info
except ImportError, ex:
sys.stderr.write('Failed to import set_exc_info: %s\n' % ex)
def set_exc_info(*args): import greenlet # http://pypi.python.org/pypi/greenlet/
pass greenlet_version = getattr(greenlet, '__version__', None)
if greenlet_version:
greenlet_version_info = [int(x) for x in greenlet_version.split('.')]
if not greenlet_version or greenlet_version_info[:3] < [0, 3, 2]:
raise ImportError('''Your version of greenlet (%s) is too old (required >= 0.3.2)
You can get a newer version of greenlet from http://pypi.python.org/pypi/greenlet/''' % (greenlet_version, ))
from greenlet import greenlet, getcurrent, GreenletExit
__all__ = ['getcurrent', __all__ = ['getcurrent',
...@@ -36,24 +38,6 @@ else: ...@@ -36,24 +38,6 @@ else:
integer_types = (int, long) integer_types = (int, long)
def __import_py_magic_greenlet():
try:
from py.magic import greenlet
return greenlet
except ImportError:
pass
try:
from greenlet import greenlet
except ImportError:
greenlet = __import_py_magic_greenlet()
if greenlet is None:
raise
getcurrent = greenlet.getcurrent
GreenletExit = greenlet.GreenletExit
# In greenlet >= 0.3.2, GreenletExit is a subclass of BaseException # In greenlet >= 0.3.2, GreenletExit is a subclass of BaseException
# In greenlet <= 0.3.1, GreenletExit is a subclass of Exception # In greenlet <= 0.3.1, GreenletExit is a subclass of Exception
# Since, GreenletExit is a part of gevent's public interface, we want # Since, GreenletExit is a part of gevent's public interface, we want
...@@ -358,15 +342,10 @@ class Hub(greenlet): ...@@ -358,15 +342,10 @@ class Hub(greenlet):
sys.stderr.write('%s failed with %s\n\n' % (context, getattr(type, '__name__', 'exception'), )) sys.stderr.write('%s failed with %s\n\n' % (context, getattr(type, '__name__', 'exception'), ))
def switch(self): def switch(self):
exc_type, exc_value = sys.exc_info()[:2]
try:
switch_out = getattr(getcurrent(), 'switch_out', None) switch_out = getattr(getcurrent(), 'switch_out', None)
if switch_out is not None: if switch_out is not None:
switch_out() switch_out()
exc_clear()
return greenlet.switch(self) return greenlet.switch(self)
finally:
set_exc_info(exc_type, exc_value)
def switch_out(self): def switch_out(self):
raise AssertionError('Impossible to call blocking function in the event loop callback') raise AssertionError('Impossible to call blocking function in the event loop callback')
......
...@@ -121,9 +121,9 @@ def wrap_refcount(method): ...@@ -121,9 +121,9 @@ def wrap_refcount(method):
# OK, we don't know for sure yet. Let's search for more # OK, we don't know for sure yet. Let's search for more
if sum(deltas[-3:]) <= 0 or sum(deltas[-4:]) <= 0 or deltas[-4:].count(0) >= 2: if sum(deltas[-3:]) <= 0 or sum(deltas[-4:]) <= 0 or deltas[-4:].count(0) >= 2:
# this is suspicious, so give a few more runs # this is suspicious, so give a few more runs
limit = 10 limit = 11
else: else:
limit = 6 limit = 7
if len(deltas) >= limit: if len(deltas) >= limit:
raise AssertionError('refcount increased by %r' % (deltas, )) raise AssertionError('refcount increased by %r' % (deltas, ))
finally: finally:
......
...@@ -31,7 +31,7 @@ NOT_IMPLEMENTED = { ...@@ -31,7 +31,7 @@ NOT_IMPLEMENTED = {
COULD_BE_MISSING = { COULD_BE_MISSING = {
'socket': ['create_connection', 'RAND_add', 'RAND_egd', 'RAND_status']} 'socket': ['create_connection', 'RAND_add', 'RAND_egd', 'RAND_status']}
NO_ALL = ['gevent.threading'] NO_ALL = ['gevent.threading', 'gevent._util']
class Test(unittest.TestCase): class Test(unittest.TestCase):
...@@ -159,13 +159,13 @@ are missing from %r: ...@@ -159,13 +159,13 @@ are missing from %r:
self.check_implements_presence_justified() self.check_implements_presence_justified()
if self.stdlib_module is None:
return
# use __all__ as __implements__ # use __all__ as __implements__
if self.__implements__ is None: if self.__implements__ is None:
self.__implements__ = sorted(self.module.__all__) self.__implements__ = sorted(self.module.__all__)
if self.stdlib_module is None:
return
self.set_stdlib_all() self.set_stdlib_all()
self.check_implements_subset_of_stdlib_all() self.check_implements_subset_of_stdlib_all()
self.check_implements_actually_implements() self.check_implements_actually_implements()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment