[pypy-svn] r39230 - in pypy/dist/pypy/lib/distributed: . demo test

fijal at codespeak.net fijal at codespeak.net
Tue Feb 20 14:01:41 CET 2007


Author: fijal
Date: Tue Feb 20 14:01:33 2007
New Revision: 39230

Added:
   pypy/dist/pypy/lib/distributed/demo/
   pypy/dist/pypy/lib/distributed/demo/show.py
Modified:
   pypy/dist/pypy/lib/distributed/__init__.py
   pypy/dist/pypy/lib/distributed/objkeeper.py
   pypy/dist/pypy/lib/distributed/protocol.py
   pypy/dist/pypy/lib/distributed/test/test_distributed.py
Log:
Few fixes, failing test and a demo


Modified: pypy/dist/pypy/lib/distributed/__init__.py
==============================================================================
--- pypy/dist/pypy/lib/distributed/__init__.py	(original)
+++ pypy/dist/pypy/lib/distributed/__init__.py	Tue Feb 20 14:01:33 2007
@@ -1,2 +1,6 @@
 
-from protocol import RemoteProtocol, test_env, remote_loop
+try:
+    from protocol import RemoteProtocol, test_env, remote_loop
+except ImportError:
+    # UGH. This is needed for tests
+    pass

Added: pypy/dist/pypy/lib/distributed/demo/show.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lib/distributed/demo/show.py	Tue Feb 20 14:01:33 2007
@@ -0,0 +1,47 @@
+""" Notes: you need to have pylib, greenexecnet, greensock2 and pypeers
+symlinked in pypy/lib dir
+"""
+
+import sys
+import greenexecnet
+import py
+
+remote = py.code.Source("""
+class X:
+    def __init__(self, z):
+        self.z = z
+        
+    def meth(self, x):
+        return self.z + x()
+
+    def raising(self):
+        1/0
+        
+x = X(3)
+
+from distributed import RemoteProtocol, remote_loop
+remote_loop(RemoteProtocol(channel.send, channel.receive, {'x':x}))
+""")
+
+if __name__ == '__main__':
+    gw = greenexecnet.SshGateway('localhost', remotepython=sys.executable)
+    ch = gw.remote_exec(str(remote))
+    from distributed import RemoteProtocol
+    rp = RemoteProtocol(ch.send, ch.receive, {})
+    x = rp.get_remote("x")
+
+    # examples:
+    # def f():
+    #    return 3
+    # x.meth(f) # should be 3 + 3, but f called locally
+
+    # try:
+    #   x.raising
+    # except:
+    #   import sys
+    #   e = sys.exc_info()
+    # e[2].tb_next.tb_next.tb_frame.f_locals['self'].z
+    # # should be 3 (remote z), note that one frame is not cut properly
+    
+    import code
+    code.interact(local=locals())

Modified: pypy/dist/pypy/lib/distributed/objkeeper.py
==============================================================================
--- pypy/dist/pypy/lib/distributed/objkeeper.py	(original)
+++ pypy/dist/pypy/lib/distributed/objkeeper.py	Tue Feb 20 14:01:33 2007
@@ -26,8 +26,6 @@
         return len(self.exported_objects) - 1
     
     def ignore(self, key, value):
-        #key not in ('__dict__', '__weakref__', '__class__', '__new__',
-        #        '__base__', '__flags__', '__mro__', '__bases__')]
         if key in ('__dict__', '__weakref__', '__class__', '__new__'):
             return True
         if isinstance(value, GetSetDescriptor):
@@ -39,8 +37,6 @@
             return self.exported_types[tp]
         except KeyError:
             print "Registering type %s as %s" % (tp, self.exported_types_id)
-            if str(tp).find('getset') != -1:
-                import pdb;pdb.set_trace()
             self.exported_types[tp] = self.exported_types_id
             tp_id = self.exported_types_id
             self.exported_types_id += 1
@@ -60,14 +56,11 @@
         if '__doc__' in _dict:
             d['__doc__'] = protocol.unwrap(_dict['__doc__'])
         tp = type(_name, (object,), d)
+        # Make sure we cannot instantiate the remote type
         self.remote_types[type_id] = tp
         for key, value in _dict.items():
             if key != '__doc__':
-                try:
-                    setattr(tp, key, protocol.unwrap(value))
-                except TypeError:
-                    # XXX this stays here for debugging reasons
-                    import pdb;pdb.set_trace()
+                setattr(tp, key, protocol.unwrap(value))
                     
     def get_type(self, id):
         return self.remote_types[id]

Modified: pypy/dist/pypy/lib/distributed/protocol.py
==============================================================================
--- pypy/dist/pypy/lib/distributed/protocol.py	(original)
+++ pypy/dist/pypy/lib/distributed/protocol.py	Tue Feb 20 14:01:33 2007
@@ -49,9 +49,11 @@
 """
 TODO list:
 
-1. Add some garbage collection
-2. Add caching of objects that are presented (even on name level)
-3. Add exceptions, frames and error handling
+1. Garbage collection - we would like probably to use weakrefs, but
+   since they're not perfectly working in pypy, let's live it alone for now
+2. Some error handling - exceptions are working, there are still some
+   applications where it all explodes.
+3. Support inheritance and recursive types
 """
 
 from pypymagic import pypy_repr

Modified: pypy/dist/pypy/lib/distributed/test/test_distributed.py
==============================================================================
--- pypy/dist/pypy/lib/distributed/test/test_distributed.py	(original)
+++ pypy/dist/pypy/lib/distributed/test/test_distributed.py	Tue Feb 20 14:01:33 2007
@@ -197,3 +197,14 @@
             #assert tb.tb_next is None
         else:
             raise AssertionError("Did not raise")
+
+    def test_instantiate_remote_type(self):
+        py.test.skip("Land of infinite recursion")
+        from distributed import test_env
+
+        class C:
+            pass
+
+        protocol = test_env({'C':C})
+        xC = protocol.get_remote('C')
+        xC()



More information about the Pypy-commit mailing list