Skip to content

Instantly share code, notes, and snippets.

@cbsmith
Created February 18, 2015 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbsmith/8da600d747158660444a to your computer and use it in GitHub Desktop.
Save cbsmith/8da600d747158660444a to your computer and use it in GitHub Desktop.
monkey patch all
def patch_all(socket=True, dns=True, time=True, select=True, thread=True, os=True, ssl=True, httplib=False,
subprocess=False, sys=False, aggressive=True, Event=False):
"""Do all of the default monkey patching (calls every other function in this module."""
# order is important
if os:
patch_os()
if time:
patch_time()
if thread:
patch_thread(Event=Event)
# sys must be patched after thread. in other cases threading._shutdown will be
# initiated to _MainThread with real thread ident
if sys:
patch_sys()
if socket:
patch_socket(dns=dns, aggressive=aggressive)
if select:
patch_select(aggressive=aggressive)
if ssl:
if version_info[:2] > (2, 5):
patch_ssl()
else:
try:
patch_ssl()
except ImportError:
pass # in Python 2.5, 'ssl' is a standalone package not included in stdlib
if httplib:
raise ValueError('gevent.httplib is no longer provided, httplib must be False')
if subprocess:
patch_subprocess()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment