Skip to content

Commit

Permalink
Do not allow failed patching to stop execution
Browse files Browse the repository at this point in the history
There are some cases where monkey_patching cannot always be performed
early enough; such as sphinx autodoc importing. To help handle these
cases, exceptions during patching are logged and execution is allowed
to continue.

This fixed an issue in OpenStack Manila docs generation caused by an
upgrade to eventlet 0.35.0.
  • Loading branch information
jayofdoom committed Jan 30, 2024
1 parent d467343 commit 48b1ad1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Unreleased
==========

0.35.1
======

* [fix] Do not allow failed patching to stop execution https://github.com/eventlet/eventlet/pull/907

0.35.0
======

Expand Down
18 changes: 14 additions & 4 deletions eventlet/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,20 @@ def upgrade_or_traverse(obj):
except TypeError:
pass
else:
for k, v in list(container_vars.items()):
new = upgrade_or_traverse(v)
if new is not None:
setattr(container, k, new)
# If we get here, we're operating on an object that could
# be doing strange things. If anything bad happens, error and
# warn the eventlet user to monkey_patch earlier.
try:
for k, v in list(container_vars.items()):
new = upgrade_or_traverse(v)
if new is not None:
setattr(container, k, new)
except:
import logging
logger = logging.Logger("eventlet")
logger.exception("An exception was thrown while monkey_patching for eventlet. "
"to fix this error make sure you run eventlet.monkey_patch() "
"before importing any other modules.", exc_info=True)


def _convert_py3_rlock(old, tid):
Expand Down
18 changes: 18 additions & 0 deletions tests/isolated/patcher_existing_locks_exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
__test__ = False


class BadDict(dict):
def items(self):
raise Exception()


if __name__ == '__main__':
import threading
test_lock = threading.RLock()
test_lock.acquire()
baddict = BadDict(testkey='testvalue')

import eventlet
eventlet.monkey_patch()

print('pass')
4 changes: 4 additions & 0 deletions tests/patcher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,7 @@ def test_open_kwargs():

def test_patcher_existing_locks():
tests.run_isolated("patcher_existing_locks_preexisting.py")


def test_patcher_existing_locks_exception():
tests.run_isolated("patcher_existing_locks_exception.py")

0 comments on commit 48b1ad1

Please sign in to comment.