Skip to content

Commit 12329c7

Browse files
committed
wrap ki protection locals demos in async def so they work
1 parent 0b2dd1a commit 12329c7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

docs/source/reference-lowlevel.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,12 @@ These transitions are accomplished using two function decorators:
389389
inner = trio.lowlevel.enable_ki_protection(inner)
390390
return inner()
391391

392-
assert example(False) == False
393-
assert example(True) == True # once protected ...
394-
assert example(False) == True # ... always protected
392+
async def amain():
393+
assert example(False) == False
394+
assert example(True) == True # once protected ...
395+
assert example(False) == True # ... always protected
396+
397+
trio.run(amain)
395398

396399
If you really need conditional protection, you can achieve it by giving each
397400
KI-protected instance of the closure its own code object::
@@ -404,9 +407,12 @@ These transitions are accomplished using two function decorators:
404407
inner = trio.lowlevel.enable_ki_protection(inner)
405408
return inner()
406409

407-
assert example(False) == False
408-
assert example(True) == True
409-
assert example(False) == False
410+
async def amain():
411+
assert example(False) == False
412+
assert example(True) == True
413+
assert example(False) == False
414+
415+
trio.run(amain)
410416

411417
(This isn't done by default because it carries some memory overhead and reduces
412418
the potential for specializing optimizations in recent versions of CPython.)

0 commit comments

Comments
 (0)