eventlet time sleep

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.

eventlet.patcher.monkey_patch(os=None, select=None, socket=None, thread=None, time=None, psycopg=None)

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 ssl module if present; and thread, which patches thread, threading, and Queue.

Here’s an example of using monkey_patch to patch only a few modules:

import eventlet
eventlet.monkey_patch(socket=True, select=True)
原文地址:https://www.cnblogs.com/lexus/p/1841549.html