Skip to content

Commit ac6ae56

Browse files
committed
trio.hazmat > lowlevel
1 parent 3d37218 commit ac6ae56

7 files changed

Lines changed: 27 additions & 27 deletions

File tree

docs/source/principles.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Most *synchronous* asyncio or Trio functions (:meth:`trio.Event.set`,
8181
asyncio or Trio context, and work equally well regardless of the
8282
flavor of function calling them. The exceptions are functions that
8383
access the current task (:func:`asyncio.current_task`,
84-
:func:`trio.hazmat.current_task`, and anything that calls them),
84+
:func:`trio.lowlevel.current_task`, and anything that calls them),
8585
because there's only a meaningful concept of the current *foo* task
8686
when a *foo*-flavored function is executing. For example, this means
8787
context managers that set a timeout on their body (``with

tests/interop/test_calls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ async def test_asyncio_trio_cancel_out(self, loop):
302302
async def cancelled_trio(seen):
303303
seen.flag |= 1
304304
await trio.sleep(0.01)
305-
scope = trio.hazmat.current_task()._cancel_status._scope
305+
scope = trio.lowlevel.current_task()._cancel_status._scope
306306
scope.cancel()
307307
seen.flag |= 2
308308
await trio.sleep(0.01)

tests/test_misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def close_no_stop():
3030
async def test_too_many_stops(self):
3131
with trio.move_on_after(1) as scope:
3232
async with trio_asyncio.open_loop() as loop:
33-
await trio.hazmat.checkpoint()
33+
await trio.lowlevel.checkpoint()
3434
loop.stop()
3535
assert not scope.cancelled_caught, \
3636
"Possible deadlock after manual call to loop.stop"

trio_asyncio/_base.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from selectors import _BaseSelectorImpl, EVENT_READ, EVENT_WRITE
1818

1919
try:
20-
from trio.hazmat import wait_for_child
20+
from trio.lowlevel import wait_for_child
2121
except ImportError:
2222
from ._child import wait_for_child
2323

@@ -27,11 +27,11 @@
2727
_mswindows = (sys.platform == "win32")
2828

2929
try:
30-
_wait_readable = trio.hazmat.wait_readable
31-
_wait_writable = trio.hazmat.wait_writable
30+
_wait_readable = trio.lowlevel.wait_readable
31+
_wait_writable = trio.lowlevel.wait_writable
3232
except AttributeError:
33-
_wait_readable = trio.hazmat.wait_socket_readable
34-
_wait_writable = trio.hazmat.wait_socket_writable
33+
_wait_readable = trio.lowlevel.wait_socket_readable
34+
_wait_writable = trio.lowlevel.wait_socket_writable
3535

3636

3737
class _Clear:
@@ -466,7 +466,7 @@ def add_reader(self, fd, callback, *args):
466466
ready for reading.
467467
468468
This creates a new Trio task. You may want to use "await
469-
:obj:`trio.hazmat.wait_readable` (fd)" instead, or
469+
:obj:`trio.lowlevel.wait_readable` (fd)" instead, or
470470
471471
:param fd: Either an integer (Unix file descriptor) or an object
472472
with a ``fileno`` method providing one.
@@ -516,7 +516,7 @@ def add_writer(self, fd, callback, *args):
516516
ready for writing.
517517
518518
This creates a new Trio task. You may want to use "await
519-
:obj:`trio.hazmat.wait_writable` (fd) instead, or
519+
:obj:`trio.lowlevel.wait_writable` (fd) instead, or
520520
521521
:param fd: Either an integer (Unix file descriptor) or an object
522522
with a ``fileno`` method providing one.
@@ -614,8 +614,8 @@ async def _main_loop_init(self, nursery):
614614
if self._nursery is not None or not self._stopped.is_set():
615615
raise RuntimeError("You can't enter a loop twice")
616616
self._nursery = nursery
617-
self._task = trio.hazmat.current_task()
618-
self._token = trio.hazmat.current_trio_token()
617+
self._task = trio.lowlevel.current_task()
618+
self._token = trio.lowlevel.current_trio_token()
619619

620620
async def _main_loop(self, task_status=trio.TASK_STATUS_IGNORED):
621621
"""Run the loop by processing its event queue.

trio_asyncio/_child.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async def wait(self):
9696
async def _start_waiting(self):
9797
"""Start the background thread that waits for a specific child"""
9898
self.__event = trio.Event()
99-
self.__token = trio.hazmat.current_trio_token()
99+
self.__token = trio.lowlevel.current_trio_token()
100100

101101
self.__thread = threading.Thread(
102102
target=self._wait_thread, name="waitpid_%d" % self.__pid, daemon=True

trio_asyncio/_loop.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from ._deprecate import deprecated, warn_deprecated
1919

2020
try:
21-
from trio.hazmat import wait_for_child
21+
from trio.lowlevel import wait_for_child
2222
except ImportError:
2323
from ._child import wait_for_child
2424

@@ -103,7 +103,7 @@ class _FakedPolicy(threading.local):
103103

104104
def _in_trio_context():
105105
try:
106-
trio.hazmat.current_task()
106+
trio.lowlevel.current_task()
107107
except RuntimeError:
108108
return False
109109
else:
@@ -147,7 +147,7 @@ def get_event_loop(self):
147147
``.current_event_loop`` property.
148148
"""
149149
try:
150-
task = trio.hazmat.current_task()
150+
task = trio.lowlevel.current_task()
151151
except RuntimeError:
152152
pass
153153
else:
@@ -230,7 +230,7 @@ def _new_policy_set(new_policy):
230230

231231
def _new_run_get():
232232
try:
233-
task = trio.hazmat.current_task()
233+
task = trio.lowlevel.current_task()
234234
except RuntimeError:
235235
pass
236236
else:

trio_asyncio/_util.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ async def run_aio_future(future):
2323
This is a Trio-flavored async function.
2424
2525
"""
26-
task = trio.hazmat.current_task()
26+
task = trio.lowlevel.current_task()
2727
raise_cancel = None
2828

2929
def done_cb(_):
30-
trio.hazmat.reschedule(task, outcome.capture(future.result))
30+
trio.lowlevel.reschedule(task, outcome.capture(future.result))
3131

3232
future.add_done_callback(done_cb)
3333

@@ -38,10 +38,10 @@ def abort_cb(raise_cancel_arg):
3838
# Attempt to cancel our future
3939
future.cancel()
4040
# Keep waiting
41-
return trio.hazmat.Abort.FAILED
41+
return trio.lowlevel.Abort.FAILED
4242

4343
try:
44-
res = await trio.hazmat.wait_task_rescheduled(abort_cb)
44+
res = await trio.lowlevel.wait_task_rescheduled(abort_cb)
4545
return res
4646
except asyncio.CancelledError as exc:
4747
if raise_cancel is not None:
@@ -64,7 +64,7 @@ async def run_aio_generator(loop, async_generator):
6464
doesn't have to be). The asyncio tasks that perform each iteration
6565
of *async_generator* will run in *loop*.
6666
"""
67-
task = trio.hazmat.current_task()
67+
task = trio.lowlevel.current_task()
6868
raise_cancel = None
6969
current_read = None
7070

@@ -83,7 +83,7 @@ async def consume_next():
8383
finally:
8484
sniffio.current_async_library_cvar.reset(t)
8585

86-
trio.hazmat.reschedule(task, result)
86+
trio.lowlevel.reschedule(task, result)
8787

8888
def abort_cb(raise_cancel_arg):
8989
# Save the cancel-raising function
@@ -92,25 +92,25 @@ def abort_cb(raise_cancel_arg):
9292

9393
if not current_read:
9494
# There is no current read
95-
return trio.hazmat.Abort.SUCCEEDED
95+
return trio.lowlevel.Abort.SUCCEEDED
9696
else:
9797
# Attempt to cancel the current iterator read, do not
9898
# report success until the future was actually cancelled.
9999
already_cancelled = current_read.cancel()
100100
if already_cancelled:
101-
return trio.hazmat.Abort.SUCCEEDED
101+
return trio.lowlevel.Abort.SUCCEEDED
102102
else:
103103
# Continue dealing with the cancellation once
104104
# future.cancel() goes to the result of
105105
# wait_task_rescheduled()
106-
return trio.hazmat.Abort.FAILED
106+
return trio.lowlevel.Abort.FAILED
107107

108108
try:
109109
while True:
110110
# Schedule in asyncio that we read the next item from the iterator
111111
current_read = asyncio.ensure_future(consume_next(), loop=loop)
112112

113-
item = await trio.hazmat.wait_task_rescheduled(abort_cb)
113+
item = await trio.lowlevel.wait_task_rescheduled(abort_cb)
114114

115115
if item is STOP:
116116
break

0 commit comments

Comments
 (0)