Skip to content

Commit 3db73ac

Browse files
authored
Add missing imports for Readcting to cancellation in worker threads example (#944)
1 parent 2eda004 commit 3db73ac

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

docs/threads.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,15 @@ mechanism that allows user code to voluntarily check if the host task's scope ha
214214
and if it has, raise a cancellation exception. This can be done by simply calling
215215
:func:`from_thread.check_cancelled`::
216216

217-
from anyio import to_thread, from_thread
217+
import time
218+
219+
from anyio import to_thread, from_thread, move_on_after
218220

219221
def sync_function():
220222
while True:
221223
from_thread.check_cancelled()
222224
print("Not cancelled yet")
223-
sleep(1)
225+
time.sleep(1)
224226

225227
async def foo():
226228
with move_on_after(3):

0 commit comments

Comments
 (0)