Skip to content

Instantly share code, notes, and snippets.

@tonyseek
Last active September 8, 2016 06:39
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 tonyseek/11b1a9f85872d32bf18979ff8342679c to your computer and use it in GitHub Desktop.
Save tonyseek/11b1a9f85872d32bf18979ff8342679c to your computer and use it in GitHub Desktop.
The deadlock caused by inconsistent thread ident (RLock of logging handlers)
import logging
import itertools
import gevent.monkey
class SlowHandler(logging.Handler):
def emit(self, record):
gevent.sleep(1)
logging.basicConfig()
logger = logging.getLogger(__name__)
# gevent.monkey.patch_all()
logger.addHandler(SlowHandler())
gevent.monkey.patch_all()
def dump_sth(name):
for idx in itertools.count():
logger.warning('=> %s %s' % (name, idx))
gevent.sleep(0)
gevent.spawn(dump_sth, 'foo')
gevent.spawn(dump_sth, 'bar')
gevent.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment