Commit cc576fd4 authored by Jason Madden's avatar Jason Madden

Fix the leakchecks with a couple well-placed del statements.

parent 8f579d78
......@@ -185,7 +185,10 @@ class Traceback(object):
except:
tb = sys.exc_info()[2].tb_next
tb_set_next(tb, self.tb_next and self.tb_next.as_traceback())
return tb
try:
return tb
finally:
del tb
else:
raise RuntimeError("Cannot re-create traceback !")
......
......@@ -121,6 +121,9 @@ class Greenlet(greenlet):
def _links(self):
return deque()
def _has_links(self):
return '_links' in self.__dict__ and self._links
def _raise_exception(self):
reraise(*self.exc_info)
......@@ -351,7 +354,7 @@ class Greenlet(greenlet):
def _report_result(self, result):
self._exc_info = (None, None, None)
self.value = result
if self._links and not self._notifier:
if self._has_links() and not self._notifier:
self._notifier = self.parent.loop.run_callback(self._notify_links)
def _report_error(self, exc_info):
......@@ -361,10 +364,13 @@ class Greenlet(greenlet):
self._exc_info = exc_info[0], exc_info[1], dump_traceback(exc_info[2])
if self._links and not self._notifier:
if self._has_links() and not self._notifier:
self._notifier = self.parent.loop.run_callback(self._notify_links)
self.parent.handle_error(self, *exc_info)
try:
self.parent.handle_error(self, *exc_info)
finally:
del exc_info
def run(self):
try:
......
......@@ -47,6 +47,8 @@ else:
gettotalrefcount = getattr(sys, 'gettotalrefcount', None)
OPTIONAL_MODULES = ['resolver_ares']
class ExpectedException(Exception):
"""An exception whose traceback should be ignored"""
def wrap_switch_count_check(method):
@wraps(method)
......@@ -93,7 +95,7 @@ def wrap_refcount(method):
return method
# Some builtin things that we ignore
IGNORED_TYPES = (tuple, dict, types.FrameType)
IGNORED_TYPES = (tuple, dict, types.FrameType, types.TracebackType)
def type_hist():
import collections
......@@ -328,12 +330,20 @@ _original_Hub = gevent.hub.Hub
class CountingHub(_original_Hub):
EXPECTED_TEST_ERROR = (ExpectedException,)
switch_count = 0
def switch(self, *args):
self.switch_count += 1
return _original_Hub.switch(self, *args)
def handle_error(self, context, type, value, tb):
if issubclass(type, self.EXPECTED_TEST_ERROR):
# Don't print these to cut down on the noise in the test logs
return
return _original_Hub.handle_error(self, context, type, value, tb)
if gettotalrefcount is None:
gevent.hub.Hub = CountingHub
......@@ -411,10 +421,6 @@ class GenericGetTestCase(TestCase):
self.cleanup()
class ExpectedException(Exception):
"""An exception whose traceback should be ignored"""
def walk_modules(basedir=None, modpath=None, include_so=False, recursive=False):
if PYPY:
include_so = False
......
......@@ -32,7 +32,7 @@ DELAY = 0.01
greentest.TestCase.error_fatal = False
class ExpectedError(Exception):
class ExpectedError(greentest.ExpectedException):
pass
......
......@@ -57,7 +57,6 @@ class PoolBasicTests(TestCase):
try:
pool.apply(raiser)
except ExpectedException:
import traceback; traceback.print_exc()
pass
else:
self.fail("Should have raised ExpectedException")
......
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