Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion eventlet/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,23 @@ def _green_existing_locks():
elif py3_style and not isinstance(obj, pyrlock_type):
_fix_py3_rlock(obj, tid)

if sys.version_info < (3, 10):
# Older py3 won't have RLocks show up in gc.get_objects() -- see
# https://github.com/eventlet/eventlet/issues/546 -- so green a handful
# that we know are significant
import logging
if isinstance(logging._lock, rlock_type):
_fix_py3_rlock(logging._lock, tid)
logging._acquireLock()
try:
for ref in logging._handlerList:
handler = ref()
if handler and isinstance(handler.lock, rlock_type):
_fix_py3_rlock(handler.lock, tid)
del handler
finally:
logging._releaseLock()


def _fix_py2_rlock(rlock, tid):
import eventlet.green.threading
Expand Down Expand Up @@ -465,7 +482,7 @@ def _fix_py3_rlock(old, tid):
pass
else:
for k, v in ref_vars.items():
if v == old:
if v is old:
setattr(ref, k, new)


Expand Down
24 changes: 24 additions & 0 deletions tests/isolated/patcher_existing_logging_module_lock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# https://github.com/eventlet/eventlet/issues/730
# https://github.com/eventlet/eventlet/pull/754
__test__ = False


if __name__ == "__main__":
import logging
import threading

handler = logging.Handler()
logger = logging.Logger("test")
logger.addHandler(handler)

# Initially these are standard Python RLocks:
assert not isinstance(logging._lock, threading._PyRLock)
assert not isinstance(handler.lock, threading._PyRLock)

# After patching, they get converted:
import eventlet.patcher
eventlet.patcher.monkey_patch(thread=True)
assert isinstance(logging._lock, threading._PyRLock)
assert isinstance(handler.lock, threading._PyRLock)

print("pass")
4 changes: 4 additions & 0 deletions tests/patcher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ def test_patcher_existing_locks_unlocked():
tests.run_isolated('patcher_existing_locks_unlocked.py')


def test_patcher_existing_logging_module_lock():
tests.run_isolated('patcher_existing_logging_module_lock.py')


def test_importlib_lock():
tests.run_isolated('patcher_importlib_lock.py')

Expand Down