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

fijal at codespeak.net fijal at codespeak.net
Sat Apr 28 20:58:46 CEST 2007


Author: fijal
Date: Sat Apr 28 20:58:46 2007
New Revision: 42410

Modified:
   pypy/dist/pypy/lib/distributed/__init__.py
   pypy/dist/pypy/lib/distributed/protocol.py
   pypy/dist/pypy/lib/distributed/test/test_distributed.py
Log:
catch key error and report it better if object is not there.


Modified: pypy/dist/pypy/lib/distributed/__init__.py
==============================================================================
--- pypy/dist/pypy/lib/distributed/__init__.py	(original)
+++ pypy/dist/pypy/lib/distributed/__init__.py	Sat Apr 28 20:58:46 2007
@@ -1,6 +1,7 @@
 
 try:
-    from protocol import RemoteProtocol, test_env, remote_loop
+    from protocol import RemoteProtocol, test_env, remote_loop, ObjectNotFound
 except ImportError:
+    # XXX fix it
     # UGH. This is needed for tests
     pass

Modified: pypy/dist/pypy/lib/distributed/protocol.py
==============================================================================
--- pypy/dist/pypy/lib/distributed/protocol.py	(original)
+++ pypy/dist/pypy/lib/distributed/protocol.py	Sat Apr 28 20:58:46 2007
@@ -45,6 +45,9 @@
 from distributed import faker
 import sys
 
+class ObjectNotFound(Exception):
+    pass
+
 # XXX We do not make any garbage collection. We'll need it at some point
 
 """
@@ -289,8 +292,13 @@
     while 1:
         command, data = receive()
         if command == 'get':
-            # XXX: Error recovery anyone???
-            send(("finished", wrap(protocol.keeper.exported_names[data])))
+            try:
+                item = protocol.keeper.exported_names[data]
+            except KeyError:
+                send(("finished_error",data))
+            else:
+                # XXX wrapping problems catching? do we have any?
+                send(("finished", wrap(item)))
         elif command == 'call':
             id, name, args, kwargs = data
             args, kwargs = protocol.unpack_args(args, kwargs)
@@ -302,6 +310,8 @@
                 send(("finished", wrap(retval)))
         elif command == 'finished':
             return unwrap(data)
+        elif command == 'finished_error':
+            raise ObjectNotFound("Cannot find name %s" % (data,))
         elif command == 'raised':
             exc, val, tb = unwrap(data)
             raise exc, val, tb

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	Sat Apr 28 20:58:46 2007
@@ -287,3 +287,8 @@
         xX = protocol.get_remote('X')
         assert isinstance(xy, xX)
 
+    def test_key_error(self):
+        from distributed import ObjectNotFound
+        protocol = self.test_env({})
+        raises(ObjectNotFound, "protocol.get_remote('x')")
+



More information about the Pypy-commit mailing list