[py-svn] r10612 - in py/branch/py-collect/execnet: . testing

hpk at codespeak.net hpk at codespeak.net
Thu Apr 14 13:35:04 CEST 2005


Author: hpk
Date: Thu Apr 14 13:35:04 2005
New Revision: 10612

Modified:
   py/branch/py-collect/execnet/gateway.py
   py/branch/py-collect/execnet/testing/test_gateway.py
Log:
fixed and simplified remote_redirect() implementation 
(but it's still not semantically nicely defined) 



Modified: py/branch/py-collect/execnet/gateway.py
==============================================================================
--- py/branch/py-collect/execnet/gateway.py	(original)
+++ py/branch/py-collect/execnet/gateway.py	Thu Apr 14 13:35:04 2005
@@ -324,16 +324,16 @@
         self.stdout = stdout 
 
     def open(self): 
-        channel = self.gateway.remote_exec("""
+        self.outchannel = self.gateway.newchannel() 
+        self.outchannel.setcallback(self.stdout.write) 
+        channel = self.gateway.remote_exec(""" 
             import sys
-            out = channel.newchannel() 
-            channel.send(out)
+            outchannel = channel.receive() 
             sys.__dict__.setdefault('_stdoutsubst', []).append(sys.stdout)
-            sys.stdout = out.open('w') 
+            sys.stdout = outchannel.open('w') 
         """)
-        self.outchannel = channel.receive() 
-        self.thread = threading.Thread(target=self.receive2file)
-        self.thread.start() 
+        channel.send(self.outchannel) 
+        channel.waitclose(1.0)
 
     def __del__(self): 
         self.close() 
@@ -342,22 +342,16 @@
         """ close redirection on remote side and wait 
             for closing. 
         """ 
-        self.gateway.remote_exec(""" 
+        c = self.gateway.remote_exec(""" 
             import sys
-            channel = sys.stdout.channel 
+            outchannel = sys.stdout.channel 
             sys.stdout = sys._stdoutsubst.pop() 
-            channel.close() 
+            outchannel.close() 
         """) 
         self.outchannel.waitclose(timeout=1.0) 
-
-    def receive2file(self): 
-        while 1:
-            try:
-                out = self.outchannel.receive()
-            except EOFError:
-                break
-            self.stdout.write(out)
-            self.stdout.flush()
+        c.waitclose(1.0)
+        #print "outchannel", self.outchannel 
+        #print "channel", c
         
 def getid(gw, cache={}):
     name = gw.__class__.__name__

Modified: py/branch/py-collect/execnet/testing/test_gateway.py
==============================================================================
--- py/branch/py-collect/execnet/testing/test_gateway.py	(original)
+++ py/branch/py-collect/execnet/testing/test_gateway.py	Thu Apr 14 13:35:04 2005
@@ -170,9 +170,10 @@
         out = py.std.StringIO.StringIO() 
         handle = self.gw.remote_redirect(stdout=out) 
         try: 
-            self.gw.remote_exec("print 42")
+            c = self.gw.remote_exec("print 42")
         finally: 
             handle.close() 
+        c.waitclose(1.0)
         s = out.getvalue() 
         assert s.strip() == "42" 
 



More information about the pytest-commit mailing list