From: Alexander Date: Fri, 27 Jan 2017 00:08:27 +0000 (+0300) Subject: add test X-Git-Tag: v4.5.0~15^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24eb6a677e7329373f3efd46da9a30f75ceb0343;p=thirdparty%2Ftornado.git add test add description --- diff --git a/tornado/gen.py b/tornado/gen.py index 60eecdb9d..ec10c6ff3 100644 --- a/tornado/gen.py +++ b/tornado/gen.py @@ -1022,6 +1022,8 @@ class Runner(object): try: yielded = self.gen.throw(*exc_info) finally: + # Break up a reference to itself + # for faster GC on CPython. exc_info = None else: yielded = self.gen.send(value) diff --git a/tornado/test/gen_test.py b/tornado/test/gen_test.py index 4c873f4b5..6abb8eab9 100644 --- a/tornado/test/gen_test.py +++ b/tornado/test/gen_test.py @@ -970,6 +970,31 @@ class GenCoroutineTest(AsyncTestCase): self.finished = True + @skipNotCPython + def test_coroutine_refcounting(self): + # On CPython, tasks and their arguments should be released immediately + # without waiting for garbage collection. + @gen.coroutine + def inner(): + class Foo(object): + pass + local_var = Foo() + self.local_ref = weakref.ref(local_var) + yield gen.coroutine(lambda: None)() + raise ValueError('Some error') + + @gen.coroutine + def inner2(): + try: + yield inner() + except ValueError: + pass + + self.io_loop.run_sync(inner2, timeout=3) + + self.assertIs(self.local_ref(), None) + self.finished = True + class GenSequenceHandler(RequestHandler): @asynchronous