| 1 |
""" |
| 2 |
Ensure pre-existing RLocks get upgraded in a variety of situations. |
| 3 |
""" |
| 4 |
|
| 5 |
import sys |
| 6 |
import threading |
| 7 |
import unittest.mock |
| 8 |
import eventlet |
| 9 |
|
| 10 |
python_lock = threading._PyRLock |
| 11 |
|
| 12 |
|
| 13 |
class NS: |
| 14 |
lock = threading.RLock() |
| 15 |
|
| 16 |
class NS2: |
| 17 |
lock = threading.RLock() |
| 18 |
|
| 19 |
dict = {1: 2, 12: threading.RLock()} |
| 20 |
list = [0, threading.RLock()] |
| 21 |
|
| 22 |
|
| 23 |
def ensure_upgraded(lock): |
| 24 |
if not isinstance(lock, python_lock): |
| 25 |
raise RuntimeError(lock) |
| 26 |
|
| 27 |
|
| 28 |
if __name__ == '__main__': |
| 29 |
# These extra print()s caused either test failures or segfaults until |
| 30 |
# https://github.com/eventlet/eventlet/issues/864 was fixed. |
| 31 |
if sys.version_info[:2] > (3, 9): |
| 32 |
print(unittest.mock.NonCallableMock._lock) |
| 33 |
print(NS.lock) |
| 34 |
# unittest.mock imports asyncio, so clear out asyncio. |
| 35 |
for name in list(sys.modules.keys()): |
| 36 |
if name.startswith("asyncio"): |
| 37 |
del sys.modules[name] |
| 38 |
eventlet.monkey_patch() |
| 39 |
ensure_upgraded(NS.lock) |
| 40 |
ensure_upgraded(NS.NS2.lock) |
| 41 |
ensure_upgraded(NS.dict[12]) |
| 42 |
ensure_upgraded(NS.list[1]) |
| 43 |
if sys.version_info[:2] > (3, 9): |
| 44 |
ensure_upgraded(unittest.mock.NonCallableMock._lock) |
| 45 |
print("pass") |