33# *************************************************************
44from __future__ import annotations
55
6+ import sys
67from typing import TYPE_CHECKING , ContextManager
78
89from ._ki import LOCALS_KEY_KI_PROTECTION_ENABLED
1415 from .._file_io import _HasFileNo
1516 from ._unbounded_queue import UnboundedQueue
1617 from ._windows_cffi import CData , Handle
17- import sys
1818
1919assert not TYPE_CHECKING or sys .platform == "win32"
2020
@@ -54,7 +54,7 @@ async def wait_readable(sock: _HasFileNo | int) -> None:
5454 if another task calls :func:`notify_closing` while this
5555 function is still working.
5656 """
57- locals () [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
57+ sys . _getframe (). f_locals [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
5858 try :
5959 return await GLOBAL_RUN_CONTEXT .runner .io_manager .wait_readable (sock )
6060 except AttributeError :
@@ -73,7 +73,7 @@ async def wait_writable(sock: _HasFileNo | int) -> None:
7373 if another task calls :func:`notify_closing` while this
7474 function is still working.
7575 """
76- locals () [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
76+ sys . _getframe (). f_locals [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
7777 try :
7878 return await GLOBAL_RUN_CONTEXT .runner .io_manager .wait_writable (sock )
7979 except AttributeError :
@@ -105,7 +105,7 @@ def notify_closing(handle: Handle | int | _HasFileNo) -> None:
105105 step, so other tasks won't be able to tell what order they happened
106106 in anyway.
107107 """
108- locals () [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
108+ sys . _getframe (). f_locals [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
109109 try :
110110 return GLOBAL_RUN_CONTEXT .runner .io_manager .notify_closing (handle )
111111 except AttributeError :
@@ -118,7 +118,7 @@ def register_with_iocp(handle: int | CData) -> None:
118118 <https://github.com/python-trio/trio/issues/26>`__ and `#52
119119 <https://github.com/python-trio/trio/issues/52>`__.
120120 """
121- locals () [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
121+ sys . _getframe (). f_locals [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
122122 try :
123123 return GLOBAL_RUN_CONTEXT .runner .io_manager .register_with_iocp (handle )
124124 except AttributeError :
@@ -131,7 +131,7 @@ async def wait_overlapped(handle_: int | CData, lpOverlapped: CData | int) -> ob
131131 <https://github.com/python-trio/trio/issues/26>`__ and `#52
132132 <https://github.com/python-trio/trio/issues/52>`__.
133133 """
134- locals () [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
134+ sys . _getframe (). f_locals [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
135135 try :
136136 return await GLOBAL_RUN_CONTEXT .runner .io_manager .wait_overlapped (
137137 handle_ , lpOverlapped
@@ -148,7 +148,7 @@ async def write_overlapped(
148148 <https://github.com/python-trio/trio/issues/26>`__ and `#52
149149 <https://github.com/python-trio/trio/issues/52>`__.
150150 """
151- locals () [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
151+ sys . _getframe (). f_locals [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
152152 try :
153153 return await GLOBAL_RUN_CONTEXT .runner .io_manager .write_overlapped (
154154 handle , data , file_offset
@@ -165,7 +165,7 @@ async def readinto_overlapped(
165165 <https://github.com/python-trio/trio/issues/26>`__ and `#52
166166 <https://github.com/python-trio/trio/issues/52>`__.
167167 """
168- locals () [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
168+ sys . _getframe (). f_locals [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
169169 try :
170170 return await GLOBAL_RUN_CONTEXT .runner .io_manager .readinto_overlapped (
171171 handle , buffer , file_offset
@@ -180,7 +180,7 @@ def current_iocp() -> int:
180180 <https://github.com/python-trio/trio/issues/26>`__ and `#52
181181 <https://github.com/python-trio/trio/issues/52>`__.
182182 """
183- locals () [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
183+ sys . _getframe (). f_locals [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
184184 try :
185185 return GLOBAL_RUN_CONTEXT .runner .io_manager .current_iocp ()
186186 except AttributeError :
@@ -193,7 +193,7 @@ def monitor_completion_key() -> ContextManager[tuple[int, UnboundedQueue[object]
193193 <https://github.com/python-trio/trio/issues/26>`__ and `#52
194194 <https://github.com/python-trio/trio/issues/52>`__.
195195 """
196- locals () [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
196+ sys . _getframe (). f_locals [LOCALS_KEY_KI_PROTECTION_ENABLED ] = True
197197 try :
198198 return GLOBAL_RUN_CONTEXT .runner .io_manager .monitor_completion_key ()
199199 except AttributeError :
0 commit comments