Anonymous avatar Anonymous committed b4a9c19

tweaks to work with the trunk version of eventlet

Comments (0)

Files changed (1)

 import uuid
 import weakref
 
-import simplejson
+try:
+    import simplejson as json
+except ImportError:
+    import json
+
+import eventlet
+from eventlet import hubs
+from eventlet import event
 
 from eventlet import api
-from eventlet import coros
 from eventlet.green import httplib
 
 from pyact import exc
 
 ## If set to true, an Actor will print out every exception, even if the parent
 ## handles the exception properly.
-NOISY_ACTORS = False
+NOISY_ACTORS = True
 
 
 class ActorError(RuntimeError):
         spawnable = Actor(spawnable)
 
     spawnable._args = (args, kw)
-    api.call_after_global(0, spawnable.switch)
+    eventlet.spawn_after(0, spawnable.switch)
     return spawnable.address
 
 
 
     spawnable._args = (args, kw)
     spawnable.add_link(api.getcurrent().address)
-    api.call_after_global(0, spawnable.switch)
+    eventlet.spawn_after(0, spawnable.switch)
     return spawnable.address
 
 
         """
         ## TODO: Copy message or come up with some way of "freezing" message
         ## so that actors do not share mutable state.
-        self._actor._cast(simplejson.dumps(message, default=handle_address))
+        self._actor._cast(json.dumps(message, default=handle_address))
 
     def call(self, method, message, timeout=None):
         """Send a message to the Actor this object addresses.
         parsed, conn = connect(self._address)
         ## TODO how to get the address of the local http server? This does not give fully
         ## qualified return addresses
-        conn.request('POST', parsed.path, simplejson.dumps(message, default=handle_address))
+        conn.request('POST', parsed.path, json.dumps(message, default=handle_address))
         resp = conn.getresponse()
 
     def kill(self):
     _mailbox = lazy_property('_p_mailbox', lambda self: [])
     _links = lazy_property('_p_links', lambda self: [])
     _exit_links = lazy_property('_p_exit_links', lambda self: [])
-    _exit_event = lazy_property('_p_exit_event', lambda self: coros.event())
+    _exit_event = lazy_property('_p_exit_event', lambda self: event.Event())
 
     address = lazy_property('_p_address', lambda self: Address(self),
         doc="""An Address is a reference to another Actor. See the Address
     actor_id = property(lambda self: self._actor_id)
 
     def __init__(self, run=None):
-        api.Greenlet.__init__(self, parent=api.get_hub().greenlet)
+        api.Greenlet.__init__(self, parent=hubs.get_hub().greenlet)
 
         if run is None:
             self._to_run = self.main
         if not patterns:
             if not self._mailbox:
                 self._waiting = True
-                api.get_hub().switch()
+                hubs.get_hub().switch()
             return {object: object}, self._mailbox.pop(0)
 
         while True:
                         return pattern, message
 
             self._waiting = True
-            api.get_hub().switch()
+            hubs.get_hub().switch()
 
     def add_link(self, address, trap_exit=True):
         """Link the Actor at the given Address to this Actor.
         
         Address uses this to insert a message into this Actor's mailbox.
         """
-        self._mailbox.append(simplejson.loads(message, object_hook=generate_address))
+        self._mailbox.append(json.loads(message, object_hook=generate_address))
         if self._waiting:
-            api.call_after_global(0, self.switch)
+            eventlet.spawn_after(0, self.switch)
 
 
 class Server(Actor):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.