| 1 |
""" |
| 2 |
This namespace represents low-level functionality not intended for daily use, |
| 3 |
but useful for extending Trio's functionality. |
| 4 |
""" |
| 5 |
|
| 6 |
# imports are renamed with leading underscores to indicate they are not part of the public API |
| 7 |
import select as _select |
| 8 |
|
| 9 |
# static checkers don't understand if importing this as _sys, so it's deleted later |
| 10 |
import sys |
| 11 |
import typing as _t |
| 12 |
|
| 13 |
# Generally available symbols |
| 14 |
from ._core import ( |
| 15 |
Abort as Abort, |
| 16 |
ParkingLot as ParkingLot, |
| 17 |
ParkingLotStatistics as ParkingLotStatistics, |
| 18 |
RaiseCancelT as RaiseCancelT, |
| 19 |
RunStatistics as RunStatistics, |
| 20 |
RunVar as RunVar, |
| 21 |
RunVarToken as RunVarToken, |
| 22 |
Task as Task, |
| 23 |
TrioToken as TrioToken, |
| 24 |
UnboundedQueue as UnboundedQueue, |
| 25 |
UnboundedQueueStatistics as UnboundedQueueStatistics, |
| 26 |
add_instrument as add_instrument, |
| 27 |
add_parking_lot_breaker as add_parking_lot_breaker, |
| 28 |
cancel_shielded_checkpoint as cancel_shielded_checkpoint, |
| 29 |
checkpoint as checkpoint, |
| 30 |
checkpoint_if_cancelled as checkpoint_if_cancelled, |
| 31 |
current_clock as current_clock, |
| 32 |
current_root_task as current_root_task, |
| 33 |
current_statistics as current_statistics, |
| 34 |
current_task as current_task, |
| 35 |
current_trio_token as current_trio_token, |
| 36 |
currently_ki_protected as currently_ki_protected, |
| 37 |
disable_ki_protection as disable_ki_protection, |
| 38 |
enable_ki_protection as enable_ki_protection, |
| 39 |
in_trio_run as in_trio_run, |
| 40 |
in_trio_task as in_trio_task, |
| 41 |
notify_closing as notify_closing, |
| 42 |
permanently_detach_coroutine_object as permanently_detach_coroutine_object, |
| 43 |
reattach_detached_coroutine_object as reattach_detached_coroutine_object, |
| 44 |
remove_instrument as remove_instrument, |
| 45 |
remove_parking_lot_breaker as remove_parking_lot_breaker, |
| 46 |
reschedule as reschedule, |
| 47 |
spawn_system_task as spawn_system_task, |
| 48 |
start_guest_run as start_guest_run, |
| 49 |
start_thread_soon as start_thread_soon, |
| 50 |
temporarily_detach_coroutine_object as temporarily_detach_coroutine_object, |
| 51 |
wait_readable as wait_readable, |
| 52 |
wait_task_rescheduled as wait_task_rescheduled, |
| 53 |
wait_writable as wait_writable, |
| 54 |
) |
| 55 |
from ._subprocess import open_process as open_process |
| 56 |
|
| 57 |
# This is the union of a subset of trio/_core/ and some things from trio/*.py. |
| 58 |
# See comments in trio/__init__.py for details. |
| 59 |
|
| 60 |
# Uses `from x import y as y` for compatibility with `pyright --verifytypes` (#2625) |
| 61 |
|
| 62 |
if sys.platform == "win32" or ( |
| 63 |
not _t.TYPE_CHECKING and "sphinx.ext.autodoc" in sys.modules |
| 64 |
): |
| 65 |
# Windows symbols |
| 66 |
from ._core import ( |
| 67 |
current_iocp as current_iocp, |
| 68 |
monitor_completion_key as monitor_completion_key, |
| 69 |
readinto_overlapped as readinto_overlapped, |
| 70 |
register_with_iocp as register_with_iocp, |
| 71 |
wait_overlapped as wait_overlapped, |
| 72 |
write_overlapped as write_overlapped, |
| 73 |
) |
| 74 |
|
| 75 |
# don't let documentation import the actual implementation |
| 76 |
if sys.platform == "win32": # pragma: no branch |
| 77 |
from ._wait_for_object import WaitForSingleObject as WaitForSingleObject |
| 78 |
|
| 79 |
if sys.platform != "win32" or ( |
| 80 |
not _t.TYPE_CHECKING and "sphinx.ext.autodoc" in sys.modules |
| 81 |
): |
| 82 |
# Unix symbols |
| 83 |
from ._unix_pipes import FdStream as FdStream |
| 84 |
|
| 85 |
# Kqueue-specific symbols |
| 86 |
if ( |
| 87 |
sys.platform != "linux" and (_t.TYPE_CHECKING or not hasattr(_select, "epoll")) |
| 88 |
) or (not _t.TYPE_CHECKING and "sphinx.ext.autodoc" in sys.modules): |
| 89 |
from ._core import ( |
| 90 |
current_kqueue as current_kqueue, |
| 91 |
monitor_kevent as monitor_kevent, |
| 92 |
wait_kevent as wait_kevent, |
| 93 |
) |
| 94 |
|
| 95 |
del sys |