Browse Source

expose async_mode and sleep from engineio

pull/31/head
Miguel Grinberg 9 years ago
parent
commit
065cc4b221
  1. 26
      socketio/server.py

26
socketio/server.py

@ -99,6 +99,8 @@ class Server(object):
self.manager = client_manager self.manager = client_manager
self.manager_initialized = False self.manager_initialized = False
self.async_mode = self.eio.async_mode
def on(self, event, handler=None, namespace=None): def on(self, event, handler=None, namespace=None):
"""Register an event handler. """Register an event handler.
@ -306,8 +308,32 @@ class Server(object):
return self.eio.handle_request(environ, start_response) return self.eio.handle_request(environ, start_response)
def start_background_task(self, target, *args, **kwargs): def start_background_task(self, target, *args, **kwargs):
"""Start a background task using the appropriate async model.
This is a utility function that applications can use to start a
background task using the method that is compatible with the
selected async mode.
:param target: the target function to execute.
:param args: arguments to pass to the function.
:param kwargs: keyword arguments to pass to the function.
This function returns an object compatible with the `Thread` class in
the Python standard library. The `start()` method on this object is
already called by this function.
"""
self.eio.start_background_task(target, *args, **kwargs) self.eio.start_background_task(target, *args, **kwargs)
def sleep(self, seconds=0):
"""Sleep for the requested amount of time using the appropriate async
model.
This is a utility function that applications can use to put a task to
sleep without having to worry about using the correct call for the
selected async mode.
"""
return self.eio.sleep(seconds)
def _emit_internal(self, sid, event, data, namespace=None, id=None): def _emit_internal(self, sid, event, data, namespace=None, id=None):
"""Send a message to a client.""" """Send a message to a client."""
if six.PY2 and not self.binary: if six.PY2 and not self.binary:

Loading…
Cancel
Save