def patch_thread(threading=True, _threading_local=True, Event=False, logging=True, existing_locks=True, _warnings=None):
 if threading:
  __import__('threading')
 patch_module('thread')
 if threading:
  threading = patch_module('threading')
  if Event:
   from gevent.event import Event
   patch_item(threading, 'Event', Event)
  if existing_locks:
   _patch_existing_locks(threading)
  if (logging and ('logging' in sys.modules)):
   logging = __import__('logging')
   patch_item(logging, '_lock', threading.RLock())
   for wr in logging._handlerList:
    handler = (wr() if callable(wr) else wr)
    if (handler is None):
     continue
    if (not hasattr(handler, 'lock')):
     raise TypeError(('Unknown/unsupported handler %r' % handler))
    handler.lock = threading.RLock()
 if _threading_local:
  _threading_local = __import__('_threading_local')
  from gevent.local import local
  patch_item(_threading_local, 'local', local)
 if (sys.version_info[:2] >= (3, 4)):
  threading = __import__('threading')
  greenlet = __import__('greenlet')
  if (threading.current_thread() == threading.main_thread()):
   main_thread = threading.main_thread()
   _greenlet = main_thread._greenlet = greenlet.getcurrent()
   from gevent.hub import sleep
   def join(timeout=None):
    if (threading.current_thread() is main_thread):
     raise RuntimeError('Cannot join current thread')
    if (_greenlet.dead or (not main_thread.is_alive())):
     return
    elif timeout:
     raise ValueError('Cannot use a timeout to join the main thread')
    else:
     while main_thread.is_alive():
      sleep(0.01)
   main_thread.join = join
   oldid = main_thread.ident
   main_thread._ident = threading.get_ident()
   if (oldid in threading._active):
    threading._active[main_thread.ident] = threading._active[oldid]
   if (oldid != main_thread.ident):
    del threading._active[oldid]
  else:
   _queue_warning('Monkey-patching not on the main thread; threading.main_thread().join() will hang from a greenlet', _warnings)

def patch_thread ( threading = True , _threading_local = True , Event = False , logging = True , existing_locks = True , _warnings = None ) : if threading : __import__ ( 'threading' ) patch_module ( 'thread' ) if threading : threading = patch_module ( 'threading' ) if Event : from gevent . event import Event patch_item ( threading , 'Event' , Event ) if existing_locks : _patch_existing_locks ( threading ) if ( logging and ( 'logging' in sys . modules ) ) : logging = __import__ ( 'logging' ) patch_item ( logging , '_lock' , threading . RLock ( ) ) for wr in logging . _handlerList : handler = ( wr ( ) if callable ( wr ) else wr ) if ( handler is None ) : continue if ( not hasattr ( handler , 'lock' ) ) : raise TypeError ( ( 'Unknown/unsupported handler %r' % handler ) ) handler . lock = threading . RLock ( ) if _threading_local : _threading_local = __import__ ( '_threading_local' ) from gevent . local import local patch_item ( _threading_local , 'local' , local ) if ( sys . version_info [ : 2 ] >= ( 3 , 4 ) ) : threading = __import__ ( 'threading' ) greenlet = __import__ ( 'greenlet' ) if ( threading . current_thread ( ) == threading . main_thread ( ) ) : main_thread = threading . main_thread ( ) _greenlet = main_thread . _greenlet = greenlet . getcurrent ( ) from gevent . hub import sleep def join ( timeout = None ) : if ( threading . current_thread ( ) is main_thread ) : raise RuntimeError ( 'Cannot join current thread' ) if ( _greenlet . dead or ( not main_thread . is_alive ( ) ) ) : return elif timeout : raise ValueError ( 'Cannot use a timeout to join the main thread' ) else : while main_thread . is_alive ( ) : sleep ( 0.01 ) main_thread . join = join oldid = main_thread . ident main_thread . _ident = threading . get_ident ( ) if ( oldid in threading . _active ) : threading . _active [ main_thread . ident ] = threading . _active [ oldid ] if ( oldid != main_thread . ident ) : del threading . _active [ oldid ] else : _queue_warning ( 'Monkey-patching not on the main thread; threading.main_thread().join() will hang from a greenlet' , _warnings )
replace the standard :mod:thread module to make it greenlet-based .