| 1 |
""" |
| 2 |
This namespace represents the core functionality that has to be built-in |
| 3 |
and deal with private internal data structures. Things in this namespace |
| 4 |
are publicly available in either trio, trio.lowlevel, or trio.testing. |
| 5 |
""" |
| 6 |
|
| 7 |
import sys |
| 8 |
import typing as _t |
| 9 |
|
| 10 |
from ._entry_queue import TrioToken |
| 11 |
from ._exceptions import ( |
| 12 |
BrokenResourceError, |
| 13 |
BusyResourceError, |
| 14 |
Cancelled, |
| 15 |
ClosedResourceError, |
| 16 |
EndOfChannel, |
| 17 |
RunFinishedError, |
| 18 |
TrioInternalError, |
| 19 |
WouldBlock, |
| 20 |
) |
| 21 |
from ._ki import currently_ki_protected, disable_ki_protection, enable_ki_protection |
| 22 |
from ._local import RunVar, RunVarToken |
| 23 |
from ._mock_clock import MockClock |
| 24 |
from ._parking_lot import ( |
| 25 |
ParkingLot, |
| 26 |
ParkingLotStatistics, |
| 27 |
add_parking_lot_breaker, |
| 28 |
remove_parking_lot_breaker, |
| 29 |
) |
| 30 |
|
| 31 |
# Imports that always exist |
| 32 |
from ._run import ( |
| 33 |
TASK_STATUS_IGNORED, |
| 34 |
CancelScope, |
| 35 |
Nursery, |
| 36 |
RunStatistics, |
| 37 |
Task, |
| 38 |
TaskStatus, |
| 39 |
add_instrument, |
| 40 |
checkpoint, |
| 41 |
checkpoint_if_cancelled, |
| 42 |
current_clock, |
| 43 |
current_effective_deadline, |
| 44 |
current_root_task, |
| 45 |
current_statistics, |
| 46 |
current_task, |
| 47 |
current_time, |
| 48 |
current_trio_token, |
| 49 |
in_trio_run, |
| 50 |
in_trio_task, |
| 51 |
notify_closing, |
| 52 |
open_nursery, |
| 53 |
remove_instrument, |
| 54 |
reschedule, |
| 55 |
run, |
| 56 |
spawn_system_task, |
| 57 |
start_guest_run, |
| 58 |
wait_all_tasks_blocked, |
| 59 |
wait_readable, |
| 60 |
wait_writable, |
| 61 |
) |
| 62 |
from ._thread_cache import start_thread_soon |
| 63 |
|
| 64 |
# Has to come after _run to resolve a circular import |
| 65 |
from ._traps import ( |
| 66 |
Abort, |
| 67 |
RaiseCancelT, |
| 68 |
cancel_shielded_checkpoint, |
| 69 |
permanently_detach_coroutine_object, |
| 70 |
reattach_detached_coroutine_object, |
| 71 |
temporarily_detach_coroutine_object, |
| 72 |
wait_task_rescheduled, |
| 73 |
) |
| 74 |
from ._unbounded_queue import UnboundedQueue, UnboundedQueueStatistics |
| 75 |
|
| 76 |
# Windows imports |
| 77 |
if sys.platform == "win32" or ( |
| 78 |
not _t.TYPE_CHECKING and "sphinx.ext.autodoc" in sys.modules |
| 79 |
): |
| 80 |
from ._run import ( |
| 81 |
current_iocp, |
| 82 |
monitor_completion_key, |
| 83 |
readinto_overlapped, |
| 84 |
register_with_iocp, |
| 85 |
wait_overlapped, |
| 86 |
write_overlapped, |
| 87 |
) |
| 88 |
# Kqueue imports |
| 89 |
if ( |
| 90 |
sys.platform != "linux" and sys.platform != "win32" and sys.platform != "android" |
| 91 |
) or (not _t.TYPE_CHECKING and "sphinx.ext.autodoc" in sys.modules): |
| 92 |
from ._run import current_kqueue, monitor_kevent, wait_kevent |
| 93 |
|
| 94 |
del sys # It would be better to import sys as _sys, but mypy does not understand it |