Anonymous avatar Anonymous committed 000b2cf

Use proper Event instead of calling hub.switch()

Calling switch() directly messed up eventlet calls like select (and I suspect others too).

Comments (0)

Files changed (1)

 import weakref
 import base64
 
+
 try:
     import simplejson as json
 except ImportError:
     (matched_pattern, message). To receive any message which is in the mailbox,
     simply call receive with no patterns.
     """
-    _waiting = False
-    _already_scheduled_switch = False
+    _wevent = None
+    _already_notified = False
     _mailbox = lazy_property('_p_mailbox', lambda self: [])
     _links = lazy_property('_p_links', lambda self: [])
     _exit_links = lazy_property('_p_exit_links', lambda self: [])
                         timer.cancel()
                     return matched_pat,matched_msg
 
-                self._waiting = True
-                self._already_scheduled_switch = False
+                self._wevent = event.Event()
+                self._already_notified = False
                 try:
-                    hubs.get_hub().switch()
+                    # wait until at least one message is sent
+                    # or timeout occurs
+                    self._wevent.wait()
                 finally:
-                    self._waiting = False
+                    self._wevent = None
+                    self._already_notified = False
+                    
 
         except ReceiveTimeout:
             return (None,None)
         Address uses this to insert a message into this Actor's mailbox.
         """
         self._mailbox.append(json.loads(message, object_hook=generate_custom))
-        if self._waiting and not self._already_scheduled_switch:
-            self._already_scheduled_switch = True
-            hubs.get_hub().schedule_call_global(0,self.switch)
+        if self._wevent and not self._already_notified:
+            self._already_notified = True
+            self._wevent.send(None)
 
 class Server(Actor):
     """An actor which responds to the call protocol by looking for the
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.