Clarified hubbage.

This commit is contained in:
Ryan Williams
2010-01-14 17:52:37 -08:00
parent 9cfa318ba0
commit 2a2323613e

View File

@@ -18,12 +18,13 @@ There is one function that is of interest as regards hubs.
.. function:: eventlet.hubs.use_hub(hub=None)
Use this to control which hub Eventlet selects. Call it with the name of the desired hub module. Make sure to do this before the application starts doing any I/O! Calling use_hub completely eliminates the old hub, and any file descriptors or timers that it had been managing will be forgotten.
Use this to control which hub Eventlet selects. Call it with the name of the desired hub module. Make sure to do this before the application starts doing any I/O! Calling use_hub completely eliminates the old hub, and any file descriptors or timers that it had been managing will be forgotten. Put the call as one of the first lines in the main module.::
>>> from eventlet import hubs
>>> hubs.use_hub("pyevent")
""" my main module using eventlet """
from eventlet import hubs
hubs.use_hub("pyevent")
Hubs are implemented as thread-local class instances. :func:`eventlet.hubs.use_hub` only operates on the current thread, so if when using multiple threads, call :func:`eventlet.hubs.use_hub` in each thread that needs a specific hub.
Hubs are implemented as thread-local class instances. :func:`eventlet.hubs.use_hub` only operates on the current thread. When using multiple threads that each need their own hub, call :func:`eventlet.hubs.use_hub` at the beginning of each thread function that needs a specific hub. In practice, it may not be necessary to specify a hub in each thread; it works to use one special hub for the main thread, and let other threads use the default hub; this hybrid hub configuration will work fine.
It is also possible to use a third-party hub module in place of one of the built-in ones. Simply pass the module itself to :func:`eventlet.hubs.use_hub`. The task of writing such a hub is a little beyond the scope of this document, it's probably a good idea to simply inspect the code of the existing hubs to see how they work.