From 50b75ca1405d26833081bcf85b5d2baeb6b0463087e71f471a3de73c032c2ea4 Mon Sep 17 00:00:00 2001 From: Daniel Garcia Date: Tue, 17 Jan 2023 16:58:40 +0000 Subject: [PATCH] - Add fix-py3-rlock.patch to make the code compatible with python 3.11, gh#eventlet/eventlet#754 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-eventlet?expand=0&rev=97 --- fix-py3-rlock.patch | 119 ++++++++++++++++++++++++++++++++++++++++ python-eventlet.changes | 6 ++ python-eventlet.spec | 4 +- 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 fix-py3-rlock.patch diff --git a/fix-py3-rlock.patch b/fix-py3-rlock.patch new file mode 100644 index 0000000..b0daebf --- /dev/null +++ b/fix-py3-rlock.patch @@ -0,0 +1,119 @@ +diff --git a/eventlet/patcher.py b/eventlet/patcher.py +index b249d6f19..4eeb93439 100644 +--- a/eventlet/patcher.py ++++ b/eventlet/patcher.py +@@ -412,6 +412,23 @@ def _green_existing_locks(): + elif py3_style and not isinstance(obj, pyrlock_type): + _fix_py3_rlock(obj) + ++ if (3, 0) <= 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) ++ logging._acquireLock() ++ try: ++ for ref in logging._handlerList: ++ handler = ref() ++ if handler and isinstance(handler.lock, rlock_type): ++ _fix_py3_rlock(handler.lock) ++ del handler ++ finally: ++ logging._releaseLock() ++ + + def _fix_py2_rlock(rlock, tid): + import eventlet.green.threading +@@ -425,7 +442,7 @@ def _fix_py2_rlock(rlock, tid): + + def _fix_py3_rlock(old): + import gc +- import threading ++ from eventlet.green import threading + new = threading._PyRLock() + while old._is_owned(): + old.release() +@@ -434,14 +451,23 @@ def _fix_py3_rlock(old): + new.acquire() + gc.collect() + for ref in gc.get_referrers(old): +- try: +- ref_vars = vars(ref) +- except TypeError: +- pass ++ if isinstance(ref, dict): ++ for k, v in ref.items(): ++ if v is old: ++ ref[k] = new ++ elif isinstance(ref, list): ++ for k, v in enumerate(ref): ++ if v is old: ++ ref[k] = new + else: +- for k, v in ref_vars.items(): +- if v == old: +- setattr(ref, k, new) ++ try: ++ ref_vars = vars(ref) ++ except TypeError: ++ pass ++ else: ++ for k, v in ref_vars.items(): ++ if v is old: ++ setattr(ref, k, new) + + + def _green_os_modules(): +diff --git a/tests/isolated/patcher_existing_logging_module_lock.py b/tests/isolated/patcher_existing_logging_module_lock.py +new file mode 100644 +index 000000000..2acad62ee +--- /dev/null ++++ b/tests/isolated/patcher_existing_logging_module_lock.py +@@ -0,0 +1,30 @@ ++# https://github.com/eventlet/eventlet/issues/730 ++# https://github.com/eventlet/eventlet/pull/754 ++__test__ = False ++ ++ ++if __name__ == "__main__": ++ import logging ++ import eventlet.patcher ++ eventlet.patcher.monkey_patch(thread=True) ++ import threading ++ ++ def take_and_release(): ++ try: ++ logging._lock.acquire() ++ finally: ++ logging._lock.release() ++ ++ assert logging._lock.acquire() ++ t = threading.Thread(target=take_and_release) ++ t.daemon = True ++ t.start() ++ ++ t.join(timeout=0.1) ++ # we should timeout, and the thread is still blocked waiting on the lock ++ assert t.is_alive() ++ ++ logging._lock.release() ++ t.join(timeout=0.1) ++ assert not t.is_alive() ++ print("pass") +diff --git a/tests/patcher_test.py b/tests/patcher_test.py +index dbf6e1c71..e8d6f3300 100644 +--- a/tests/patcher_test.py ++++ b/tests/patcher_test.py +@@ -485,6 +485,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') + diff --git a/python-eventlet.changes b/python-eventlet.changes index 63d9be3..d180bda 100644 --- a/python-eventlet.changes +++ b/python-eventlet.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Tue Jan 17 16:55:46 UTC 2023 - Daniel Garcia + +- Add fix-py3-rlock.patch to make the code compatible with python 3.11, + gh#eventlet/eventlet#754 + ------------------------------------------------------------------- Fri Dec 9 10:16:59 UTC 2022 - Thorsten Kukuk diff --git a/python-eventlet.spec b/python-eventlet.spec index 0cd3dd0..a7b4d62 100644 --- a/python-eventlet.spec +++ b/python-eventlet.spec @@ -1,7 +1,7 @@ # # spec file for package python-eventlet # -# Copyright (c) 2022 SUSE LLC +# Copyright (c) 2023 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -32,6 +32,8 @@ Patch0: denose-eventlet.patch Patch1: newdnspython.patch # PATCH-FIX-UPSTREAM https://github.com/eventlet/eventlet/pull/643 Patch2: python-eventlet-FTBFS2028.patch +# PATCH-FIX-UPSTREAM fix-py3-rlock.patch gh#eventlet/eventlet#754 +Patch3: fix-py3-rlock.patch BuildRequires: %{python_module setuptools} %if %{with python2} BuildRequires: python2-monotonic >= 1.4