Executors¶
Executors are providing the way an incoming message will be dispatched so that the message can be used for meaningful work. Different types of executors are supported, each with its own set of restrictions and capabilities.
Available Executors¶
aioeventlet¶
A message executor which integrates with eventlet and trollius.
The executor is based on eventlet executor and so is compatible with it. The executor supports trollius coroutines, explicit asynchronous programming, in addition to eventlet greenthreads, implicit asynchronous programming.
To use the executor, an aioeventlet event loop must the running in the thread executing the executor (usually the main thread). Example of code to setup and run an aioeventlet event loop for the executor (in the main thread):
import aioeventlet
import trollius
policy = aioeventlet.EventLoopPolicy()
trollius.set_event_loop_policy(policy)
def run_loop(loop):
loop.run_forever()
loop.close()
# Get the aioeventlet event loop (create it if needed)
loop = trollius.get_event_loop()
# run the event loop in a new greenthread,
# close it when it is done
eventlet.spawn(run_loop, loop)
blocking¶
A message executor which blocks the current thread.
The blocking executor’s start() method functions as a request processing loop - i.e. it blocks, processes messages and only returns when stop() is called from a dispatched method.
Method calls are dispatched in the current thread, so only a single method call can be executing at once. This executor is likely to only be useful for simple demo programs.
eventlet¶
A message executor which integrates with eventlet.
This is an executor which polls for incoming messages from a greenthread and dispatches each message in its own greenthread powered async executor.
The stop() method kills the message polling greenthread and the wait() method waits for all executor maintained greenthreads to complete.
threading¶
A message executor which integrates with threads.
A message process that polls for messages from a dispatching thread and on reception of an incoming message places the message to be processed in a thread pool to be executed at a later time.