[py-svn] r13664 - in py/branch/execnet-refactoring: . testing

arigo at codespeak.net arigo at codespeak.net
Tue Jun 21 19:09:40 CEST 2005


Author: arigo
Date: Tue Jun 21 19:09:38 2005
New Revision: 13664

Modified:
   py/branch/execnet-refactoring/gateway.py
   py/branch/execnet-refactoring/testing/test_gateway.py
Log:
GC cycles can make Channel objects stay alive a bit longer than expected.  For
a process that goes to sleep, "a bit longer" can stretch indefinitely.  This
is what made these two tests fail.


Modified: py/branch/execnet-refactoring/gateway.py
==============================================================================
--- py/branch/execnet-refactoring/gateway.py	(original)
+++ py/branch/execnet-refactoring/gateway.py	Tue Jun 21 19:09:38 2005
@@ -159,7 +159,12 @@
             channel.close(errortext)
             self.trace(errortext)
         else:
-            pass #channel.close() -- should usually be closed by Channel.__del__
+            # the channel should usually be closed by Channel.__del__.
+            # Give it a better chance now.
+            try:
+                del loc['channel']
+            except KeyError:
+                pass
 
     def _local_schedulexec(self, channel, sourcetask): 
         self.trace("dispatching exec")

Modified: py/branch/execnet-refactoring/testing/test_gateway.py
==============================================================================
--- py/branch/execnet-refactoring/testing/test_gateway.py	(original)
+++ py/branch/execnet-refactoring/testing/test_gateway.py	Tue Jun 21 19:09:38 2005
@@ -82,6 +82,10 @@
         channel = self.gw.remote_exec('pass')
         channel.waitclose(timeout=1.0)
 
+    def test_remote_exec_waitclose_2(self):
+        channel = self.gw.remote_exec('def gccycle(): pass')
+        channel.waitclose(timeout=1.0)
+
     def test_remote_exec_error_after_close(self):
         channel = self.gw.remote_exec('pass')
         channel.waitclose(timeout=1.0)
@@ -178,23 +182,21 @@
             thread.start_new_thread(producer, (channel,))
             ''')
         if earlyfree:
-            del channel
-        for i in range(5):
-            for _ in range(50):     # busy-wait
-                if l:
-                    break
-                if not earlyfree:
-                     assert not channel.isclosed()
-                time.sleep(0.04)
-            else:
+            channel = None
+        counter = 100
+        while len(l) < 5:
+            if channel and channel.isclosed():
+                break
+            counter -= 1
+            if not counter:
                 py.test.fail("timed out waiting for the answer[%d]" % i)
-            res = l.pop(0)
-            assert res == i*100
-        if not earlyfree:
-            channel.waitclose(1.0) #freed automatically at the end of producer()
-
-    def DEBUGGING_test_channel_callback_remote_freed(self):
-        self.test_channel_callback_stays_active(False)
+            time.sleep(0.04)   # busy-wait
+        assert l == [0, 100, 200, 300, 400]
+        return channel
+
+    def test_channel_callback_remote_freed(self):
+        channel = self.test_channel_callback_stays_active(False)
+        channel.waitclose(1.0) # freed automatically at the end of producer()
 
     def test_remote_redirect_stdout(self): 
         out = py.std.StringIO.StringIO() 



More information about the pytest-commit mailing list