|
2 | 2 | import os |
3 | 3 | import sys |
4 | 4 | import threading |
5 | | -from typing import Any, Optional, Type, Union |
| 5 | +from typing import Any |
| 6 | +from typing import Optional |
| 7 | +from typing import Type |
| 8 | +from typing import Union |
6 | 9 | import uuid |
7 | 10 |
|
8 | 11 | import mock |
|
17 | 20 | from tests.profiling.collector.lock_utils import init_linenos |
18 | 21 |
|
19 | 22 |
|
| 23 | +# Module-level globals for testing global lock profiling |
| 24 | +_test_global_lock = None |
| 25 | +_test_global_bar_instance = None |
| 26 | + |
| 27 | + |
20 | 28 | # Type aliases for supported classes |
21 | 29 | LockClass = Union[Type[threading.Lock], Type[threading.RLock]] |
22 | | -CollectorClass = Union[Type[collector_threading.ThreadingLockCollector], Type[collector_threading.ThreadingRLockCollector]] |
| 30 | +CollectorClass = Union[ |
| 31 | + Type[collector_threading.ThreadingLockCollector], Type[collector_threading.ThreadingRLockCollector] |
| 32 | +] |
23 | 33 |
|
24 | 34 |
|
25 | 35 | # Type aliases for supported classes |
26 | 36 | LockClass = Union[Type[threading.Lock], Type[threading.RLock]] |
27 | | -CollectorClass = Union[Type[collector_threading.ThreadingLockCollector], Type[collector_threading.ThreadingRLockCollector]] |
| 37 | +CollectorClass = Union[ |
| 38 | + Type[collector_threading.ThreadingLockCollector], Type[collector_threading.ThreadingRLockCollector] |
| 39 | +] |
28 | 40 |
|
29 | 41 | # Module-level globals for testing global lock profiling |
30 | 42 | _test_global_lock: Optional[Any] = None |
@@ -104,7 +116,7 @@ def test_user_threads_have_native_id() -> None: |
104 | 116 | for _ in range(10): |
105 | 117 | try: |
106 | 118 | # The TID should be higher than the PID, but not too high |
107 | | - native_id = getattr(t, 'native_id', None) |
| 119 | + native_id = getattr(t, "native_id", None) |
108 | 120 | if native_id is not None: |
109 | 121 | assert 0 < native_id - getpid() < 100, (native_id, getpid()) |
110 | 122 | break |
@@ -802,11 +814,11 @@ class TestBar: |
802 | 814 | def __init__(self, lock_class: LockClass) -> None: |
803 | 815 | self.bar_lock = lock_class() # !CREATE! bar_lock |
804 | 816 |
|
805 | | - def bar(self) -> None: |
| 817 | + def bar(self): |
806 | 818 | with self.bar_lock: # !ACQUIRE! !RELEASE! bar_lock |
807 | 819 | pass |
808 | 820 |
|
809 | | - def foo() -> None: |
| 821 | + def foo(): |
810 | 822 | global _test_global_lock |
811 | 823 | assert _test_global_lock is not None |
812 | 824 | with _test_global_lock: # !ACQUIRE! !RELEASE! _test_global_lock |
|
0 commit comments