gevent.monkey – Make the standard library cooperative

Make the standard library cooperative.

The functions in this module patch parts of the standard library with compatible cooperative counterparts from gevent package.

To patch an individual module call the corresponding patch_* function. For example, to patch socket module only, call patch_socket(). To patch all default modules, call gevent.monkey.patch_all().

Monkey can also patch thread and threading to become greenlet-based. So thread.start_new_thread() starts a new greenlet instead and threading.local becomes a greenlet-local storage.

Monkey patches:

gevent.monkey.patch_all(socket=True, dns=True, time=True, select=True, thread=True, os=True, ssl=True, httplib=False, aggressive=True)

Do all of the default monkey patching (calls every other function in this module.

gevent.monkey.patch_socket(dns=True, aggressive=True)

Replace the standard socket object with gevent’s cooperative sockets.

If dns is true, also patch dns functions in socket.

gevent.monkey.patch_ssl()
gevent.monkey.patch_os()

Replace os.fork() with gevent.fork().

gevent.monkey.patch_time()

Replace time.sleep() with gevent.sleep().

gevent.monkey.patch_select(aggressive=False)

Replace select.select() with gevent.select.select().

If aggressive is true (the default), also remove other blocking functions the select.

gevent.monkey.patch_thread(threading=True, _threading_local=True)

Replace the standard thread module to make it greenlet-based. If threading is true (the default), also patch threading.local. If _threading_local is true (the default), also patch _threading_local.local.

Previous topic

gevent.wsgi

Next topic

gevent.core - Low-level wrappers around libevent