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