[py-svn] r7107 - in py/dist: doc py/execnet

hpk at codespeak.net hpk at codespeak.net
Sat Oct 23 20:59:22 CEST 2004


Author: hpk
Date: Sat Oct 23 20:59:21 2004
New Revision: 7107

Modified:
   py/dist/doc/execnet.txt
   py/dist/py/execnet/gateway.py
Log:
don't use eval/repr but marshal/unmarshal. 



Modified: py/dist/doc/execnet.txt
==============================================================================
--- py/dist/doc/execnet.txt	(original)
+++ py/dist/doc/execnet.txt	Sat Oct 23 20:59:21 2004
@@ -116,9 +116,8 @@
     channel.send(item): 
         sends the given item to the other side of the channel, 
         possibly blocking if the sender queue is full. 
-        Note that each value V of the items needs to have the
-        following property (all basic types in python have it):
-        eval(repr(V)) == V. 
+        Note that items need to be marshallable (all basic 
+        python types are):
 
     channel.receive():
         receives an item that was sent from the other side, 

Modified: py/dist/py/execnet/gateway.py
==============================================================================
--- py/dist/py/execnet/gateway.py	(original)
+++ py/dist/py/execnet/gateway.py	Sat Oct 23 20:59:21 2004
@@ -1,5 +1,6 @@
 import sys, os, threading, struct, Queue, traceback
-import atexit
+
+import py 
 
 # XXX the following line should not be here
 from py.__impl__.execnet.source import Source
@@ -39,7 +40,7 @@
         for x in self.iothreads + w: 
             x.start()
         if not _gateways:
-            atexit.register(cleanup_atexit) 
+            py.std.atexit.register(cleanup_atexit) 
         _gateways.append(self) 
 
     def _stopexec(self):
@@ -198,10 +199,10 @@
     def send(self, item): 
         """sends the given item to the other side of the channel, 
         possibly blocking if the sender queue is full. 
-        Note that each value V of the items needs to have the
-        following property (all basic types in python have it):
-        eval(repr(V)) == V."""
-        self.gateway._outgoing.put(Message.CHANNEL_DATA(self.id, repr(item)))
+        Note that an item needs to be marshallable. 
+        """
+        s = py.std.marshal.dumps(item) 
+        self.gateway._outgoing.put(Message.CHANNEL_DATA(self.id, s)) 
 
     def receive(self):
         """receives an item that was sent from the other side, 
@@ -306,12 +307,12 @@
 def _setupmessages():
     #
     # EXIT_GATEWAY and STOP_RECEIVING are messages to cleanly
-    # bring down the IO connection, i.e. it shouldn't die 
-    # unexpectedly. 
+    # bring down the IO and gateway connection 
     #
     # First an EXIT_GATEWAY message is send which results
-    # on the other side's receive_handle
-    # which cleanly 
+    # on the other side's receive_handle to send send 
+    # a STOP_RECEIVING message 
+    #
     class EXIT_GATEWAY(Message):
         def received(self, gateway):
             gateway._stopexec()
@@ -339,7 +340,8 @@
     class CHANNEL_DATA(Message):
         def received(self, gateway):
             channel = gateway.channelfactory[self.channelid]
-            channel._items.put(eval(self.data)) 
+            x = py.std.marshal.loads(self.data)
+            channel._items.put(x) 
     class CHANNEL_CLOSE(Message):
         def received(self, gateway):
             channel = gateway.channelfactory[self.channelid]



More information about the pytest-commit mailing list