7
7
import random
8
8
import select
9
9
import sys
10
- import threading
11
10
import warnings
12
11
from collections import deque
13
12
from contextlib import AbstractAsyncContextManager , contextmanager , suppress
39
38
from ._entry_queue import EntryQueue , TrioToken
40
39
from ._exceptions import Cancelled , RunFinishedError , TrioInternalError
41
40
from ._instrumentation import Instruments
42
- from ._ki import KIManager , disable_ki_protection , enable_ki_protection
41
+ from ._ki import KIManager , enable_ki_protection
43
42
from ._parking_lot import GLOBAL_PARKING_LOT_BREAKER
43
+ from ._run_context import GLOBAL_RUN_CONTEXT as GLOBAL_RUN_CONTEXT
44
44
from ._thread_cache import start_thread_soon
45
45
from ._traps import (
46
46
Abort ,
83
83
StatusT_contra = TypeVar ("StatusT_contra" , contravariant = True )
84
84
85
85
FnT = TypeVar ("FnT" , bound = "Callable[..., Any]" )
86
- T = TypeVar ("T" )
87
86
RetT = TypeVar ("RetT" )
88
87
89
88
@@ -1559,14 +1558,6 @@ def raise_cancel() -> NoReturn:
1559
1558
################################################################
1560
1559
1561
1560
1562
- class RunContext (threading .local ):
1563
- runner : Runner
1564
- task : Task
1565
-
1566
-
1567
- GLOBAL_RUN_CONTEXT : Final = RunContext ()
1568
-
1569
-
1570
1561
@attrs .frozen
1571
1562
class RunStatistics :
1572
1563
"""An object containing run-loop-level debugging information.
@@ -1670,22 +1661,6 @@ def in_main_thread() -> None:
1670
1661
start_thread_soon (get_events , deliver )
1671
1662
1672
1663
1673
- @enable_ki_protection
1674
- def run_with_ki_protection_enabled (f : Callable [[T ], RetT ], v : T ) -> RetT :
1675
- try :
1676
- return f (v )
1677
- finally :
1678
- del v # for the case where f is coro.throw() and v is a (Base)Exception
1679
-
1680
-
1681
- @disable_ki_protection
1682
- def run_with_ki_protection_disabled (f : Callable [[T ], RetT ], v : T ) -> RetT :
1683
- try :
1684
- return f (v )
1685
- finally :
1686
- del v # for the case where f is coro.throw() and v is a (Base)Exception
1687
-
1688
-
1689
1664
@attrs .define (eq = False )
1690
1665
class Runner :
1691
1666
clock : Clock
@@ -2730,11 +2705,6 @@ def unrolled_run(
2730
2705
2731
2706
next_send_fn = task ._next_send_fn
2732
2707
next_send = task ._next_send
2733
- run_with = (
2734
- run_with_ki_protection_enabled
2735
- if task ._ki_protected
2736
- else run_with_ki_protection_disabled
2737
- )
2738
2708
task ._next_send_fn = task ._next_send = None
2739
2709
final_outcome : Outcome [Any ] | None = None
2740
2710
try :
@@ -2747,17 +2717,16 @@ def unrolled_run(
2747
2717
# https://github.com/python/cpython/issues/108668
2748
2718
# So now we send in the Outcome object and unwrap it on the
2749
2719
# other side.
2750
- msg = task .context .run (run_with , next_send_fn , next_send )
2720
+ msg = task .context .run (next_send_fn , next_send )
2751
2721
except StopIteration as stop_iteration :
2752
2722
final_outcome = Value (stop_iteration .value )
2753
2723
except BaseException as task_exc :
2754
2724
# Store for later, removing uninteresting top frames: 1
2755
2725
# frame we always remove, because it's this function
2756
- # another is the run_with
2757
2726
# catching it, and then in addition we remove however many
2758
2727
# more Context.run adds.
2759
2728
tb = task_exc .__traceback__
2760
- for _ in range (2 + CONTEXT_RUN_TB_FRAMES ):
2729
+ for _ in range (1 + CONTEXT_RUN_TB_FRAMES ):
2761
2730
if tb is not None : # pragma: no branch
2762
2731
tb = tb .tb_next
2763
2732
final_outcome = Error (task_exc .with_traceback (tb ))
0 commit comments