Last active
September 8, 2016 06:39
-
-
Save tonyseek/11b1a9f85872d32bf18979ff8342679c to your computer and use it in GitHub Desktop.
The deadlock caused by inconsistent thread ident (RLock of logging handlers)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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