diff options
| author | Ryan Williams <breath@alum.mit.edu> | 2010-03-27 14:47:35 -0700 |
|---|---|---|
| committer | Ryan Williams <breath@alum.mit.edu> | 2010-03-27 14:47:35 -0700 |
| commit | 4a2df235f8bc137e396db0db6fd8b13b875ddc48 (patch) | |
| tree | cc305be7c329719b514a0eb0f6adc6f6ea05aa6e /doc | |
| parent | 42054903297ab1c8d7e2df4555b62f4fe130560a (diff) | |
| download | eventlet-4a2df235f8bc137e396db0db6fd8b13b875ddc48.tar.gz | |
Simplified monkey_patch interface by removing the need for the all keyword parameter (though it still works), and adding many tests to verify that it works as intended. Simplified the tests in patcher_test overall.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/patching.rst | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/doc/patching.rst b/doc/patching.rst index 177a802..5667e11 100644 --- a/doc/patching.rst +++ b/doc/patching.rst @@ -45,13 +45,18 @@ Monkeypatching the Standard Library The other way of greening an application is simply to monkeypatch the standard library. This has the disadvantage of appearing quite magical, but the advantage of avoiding the late-binding problem. -.. function:: eventlet.patcher.monkey_patch(all=True, os=False, select=False, socket=False, thread=False, time=False) +.. function:: eventlet.patcher.monkey_patch(os=None, select=None, socket=None, thread=None, time=None) - By default, this function monkeypatches the key system modules by replacing their key elements with green equivalents. The keyword arguments afford some control over which modules are patched, in case that's important. If *all* is True, then all modules are patched regardless of the other arguments. If it's False, then the rest of the keyword arguments control patching of specific subsections of the standard library. Most patch the single module of the same name (e.g. time=True means that the time module is patched [time.sleep is patched by eventlet.sleep]). The exceptions to this rule are *socket*, which also patches the :mod:`ssl` module if present; and *thread*, which patches :mod:`thread`, :mod:`threading`, and :mod:`Queue`. + This function monkeypatches the key system modules by replacing their key elements with green equivalents. If no arguments are specified, everything is patched:: + + import eventlet + eventlet.monkey_patch() + +The keyword arguments afford some control over which modules are patched, in case that's important. Most patch the single module of the same name (e.g. time=True means that the time module is patched [time.sleep is patched by eventlet.sleep]). The exceptions to this rule are *socket*, which also patches the :mod:`ssl` module if present; and *thread*, which patches :mod:`thread`, :mod:`threading`, and :mod:`Queue`. - Here's an example of using monkey_patch to patch only a few modules:: + Here's an example of using monkey_patch to patch only a few modules:: import eventlet - eventlet.monkey_patch(all=False, socket=True, select=True) - - It is important to call :func:`~eventlet.patcher.monkey_patch` as early in the lifetime of the application as possible. Try to do it as one of the first lines in the main module. The reason for this is that sometimes there is a class that inherits from a class that needs to be greened -- e.g. a class that inherits from socket.socket -- and inheritance is done at import time, so therefore the monkeypatching should happen before the derived class is defined. It's safe to call monkey_patch multiple times.
\ No newline at end of file + eventlet.monkey_patch(socket=True, select=True) + + It is important to call :func:`~eventlet.patcher.monkey_patch` as early in the lifetime of the application as possible. Try to do it as one of the first lines in the main module. The reason for this is that sometimes there is a class that inherits from a class that needs to be greened -- e.g. a class that inherits from socket.socket -- and inheritance is done at import time, so therefore the monkeypatching should happen before the derived class is defined. It's safe to call monkey_patch multiple times. |
