[pypy-svn] r34635 - in pypy/dist/pypy/lib: . test2

fijal at codespeak.net fijal at codespeak.net
Wed Nov 15 17:44:54 CET 2006


Author: fijal
Date: Wed Nov 15 17:44:51 2006
New Revision: 34635

Modified:
   pypy/dist/pypy/lib/distributed.py
   pypy/dist/pypy/lib/test2/test_distributed.py
Log:
First real tests using stackless


Modified: pypy/dist/pypy/lib/distributed.py
==============================================================================
--- pypy/dist/pypy/lib/distributed.py	(original)
+++ pypy/dist/pypy/lib/distributed.py	Wed Nov 15 17:44:51 2006
@@ -128,10 +128,10 @@
         args, kwargs = self.unpack_args(args, kwargs)
         return getattr(obj, name)(*args, **kwargs)
 
-def remote_loop(send, receive, protocol=None):
+def remote_loop(send, receive, exported_names, protocol=None):
     # the simplest version possible, without any concurrency and such
     if protocol is None:
-        protocol = RemoteProtocol(send, receive, {})
+        protocol = RemoteProtocol(send, receive, exported_names)
     wrap = protocol.wrap
     unwrap = protocol.unwrap
     # we need this for wrap/unwrap
@@ -142,9 +142,8 @@
             send(wrap(protocol.exported_names[data]))
         elif command == 'call':
             id, name, args, kwargs = data
-            args, kwargs = unpack_args(args, kwargs)
-            assert not 'Transparent' in pypy_repr(protocol.objs[id])
-            retval = getattr(protocol.objs[id], name)(args, kwargs)
+            args, kwargs = protocol.unpack_args(args, kwargs)
+            retval = getattr(protocol.objs[id], name)(*args, **kwargs)
             send(("finished", wrap(retval)))
         elif command == 'finished':
             return unwrap(data)
@@ -178,19 +177,13 @@
     def perform(self, name, *args, **kwargs):
         return self.protocol.perform(self.id, name, *args, **kwargs)
 
-def bootstrap(gw):
-    import py
-    import sys
-    return gw.remote_exec(py.code.Source(sys.modules[__name__], "remote_loop(channel.send, channel.receive)"))
-
-
-##class RemoteFunction(object):
-##    def __init__(self, channel, name):
-##        channel.send(protocol.get(name))
-##        self.channel = channel
-##        self.id = protocol.id(channel.receive())
-##        self.fun = proxy(types.FunctionType, self.perform)
-##    
-##    def perform(self, name, *args, **kwargs):
-##        self.channel.send(protocol.pack_call(self.id, name, args, kwargs))
-##        return protocol.unpack(self.channel.receive())
+def test_env(exported_names):
+    from stackless import channel, tasklet, run
+    inp, out = channel(), channel()
+    tasklet(remote_loop)(inp.send, out.receive, exported_names)
+    return RemoteProtocol(out.send, inp.receive)
+
+#def bootstrap(gw):
+#    import py
+#    import sys
+#    return gw.remote_exec(py.code.Source(sys.modules[__name__], "remote_loop(channel.send, channel.receive)"))

Modified: pypy/dist/pypy/lib/test2/test_distributed.py
==============================================================================
--- pypy/dist/pypy/lib/test2/test_distributed.py	(original)
+++ pypy/dist/pypy/lib/test2/test_distributed.py	Wed Nov 15 17:44:51 2006
@@ -11,7 +11,8 @@
 
 class AppTestDistributed(object):
     def setup_class(cls):
-        cls.space = gettestobjspace(**{"objspace.std.withtproxy": True})
+        cls.space = gettestobjspace(**{"objspace.std.withtproxy": True,
+            "usemodules":("_stackless",)})
 
     def test_init(self):
         import distributed
@@ -53,12 +54,12 @@
         item = unwrap(wrap(f))
         assert item(3, 2) == 5
 
-    def test_remote_protocol_call(self):
+    def test_simulation_call(self):
         def f(x, y):
             return x + y
         
         import types
-        from distributed import RemoteProtocol, bootstrap
+        from distributed import RemoteProtocol
         import sys
 
         data = []
@@ -68,3 +69,12 @@
         fun = protocol.get_remote("f")
         assert isinstance(fun, types.FunctionType)
         assert fun(2, 3) == 5
+
+    def test_remote_protocol_call(self):
+        def f(x, y):
+            return x + y
+        
+        from distributed import test_env
+        protocol = test_env({"f": f})
+        fun = protocol.get_remote("f")
+        assert fun(2, 3) == 5



More information about the Pypy-commit mailing list