]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
add test
authorAlexander <homm86@gmail.com>
Fri, 27 Jan 2017 00:08:27 +0000 (03:08 +0300)
committerAlexander <homm86@gmail.com>
Fri, 27 Jan 2017 00:08:27 +0000 (03:08 +0300)
add description

tornado/gen.py
tornado/test/gen_test.py

index 60eecdb9d13a26a671d06e8567fd301041dcf8fb..ec10c6ff35705a4af8b20b8f2aca872d0e79fe21 100644 (file)
@@ -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)
index 4c873f4b5a580b0d68bfdce4ec7e48148caf56e4..6abb8eab94be8cb71bf4aa356e393a5dd8df4e3e 100644 (file)
@@ -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