[py-svn] r40039 - in py/branch/lessthread/py/execnet: . testing

hpk at codespeak.net hpk at codespeak.net
Wed Mar 7 18:10:58 CET 2007


Author: hpk
Date: Wed Mar  7 18:10:57 2007
New Revision: 40039

Modified:
   py/branch/lessthread/py/execnet/gateway.py
   py/branch/lessthread/py/execnet/testing/test_gateway.py
Log:
providing a nice error/message when you
try to execute on a remote gateway that
does not allow it (which is the default now)



Modified: py/branch/lessthread/py/execnet/gateway.py
==============================================================================
--- py/branch/lessthread/py/execnet/gateway.py	(original)
+++ py/branch/lessthread/py/execnet/gateway.py	Wed Mar  7 18:10:57 2007
@@ -24,7 +24,7 @@
     ThreadOut = py._thread.ThreadOut 
 
 import os
-debug = 0 # open('/tmp/execnet-debug-%d' % os.getpid()  , 'wa')
+debug = open('/tmp/execnet-debug-%d' % os.getpid()  , 'wa')
 
 sysex = (KeyboardInterrupt, SystemExit)
 class StopExecLoop(Exception):
@@ -149,6 +149,10 @@
     def _local_schedulexec(self, channel, sourcetask):
         if self._requestqueue is not None:
             self._requestqueue.put((channel, sourcetask)) 
+        else:
+            # we will not execute, let's send back an error
+            # to inform the other side
+            channel.close("execution disallowed")
 
     def _servemain(self, joining=True):
         from sys import exc_info

Modified: py/branch/lessthread/py/execnet/testing/test_gateway.py
==============================================================================
--- py/branch/lessthread/py/execnet/testing/test_gateway.py	(original)
+++ py/branch/lessthread/py/execnet/testing/test_gateway.py	Wed Mar  7 18:10:57 2007
@@ -372,6 +372,18 @@
         res = channel.receive()
         assert res == 42
 
+    def test_non_reverse_execution(self):
+        gw = self.gw
+        c1 = gw.remote_exec("""
+            c = channel.gateway.remote_exec("pass")
+            try:
+                c.waitclose()
+            except c.RemoteError, e: 
+                channel.send(str(e))
+        """)
+        text = c1.receive()
+        assert text.find("execution disallowed") != -1 
+    
 #class TestBlockingIssues: 
 #    def test_join_blocked_execution_gateway(self): 
 #        gateway = py.execnet.PopenGateway() 
@@ -497,7 +509,7 @@
     res = c1.receive()
     assert res == 42
     gw.exit()
-    
+
 def test_threads_twice():
     gw = py.execnet.PopenGateway()
     gw.remote_init_threads(3)



More information about the pytest-commit mailing list