Skip to content

Commit 9770d62

Browse files
committed
v3/TUTORIAL.md Add note re global exception handler.
1 parent 82e0fb2 commit 9770d62

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

v3/TUTORIAL.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ queued for execution.
12301230

12311231
During development it is often best if untrapped exceptions stop the program
12321232
rather than merely halting a single task. This can be achieved by setting a
1233-
global exception handler.
1233+
global exception handler. This debug aid is not CPython compatible:
12341234
```python
12351235
import uasyncio as asyncio
12361236
import sys
@@ -1239,16 +1239,15 @@ def _handle_exception(loop, context):
12391239
print('Global handler')
12401240
sys.print_exception(context["exception"])
12411241
#loop.stop()
1242-
sys.exit() # Drastic, but loop.stop() does not currently work
1243-
1244-
loop = asyncio.get_event_loop()
1245-
loop.set_exception_handler(_handle_exception)
1242+
sys.exit() # Drastic - loop.stop() does not work when used this way
12461243

12471244
async def bar():
12481245
await asyncio.sleep(0)
12491246
1/0 # Crash
12501247

12511248
async def main():
1249+
loop = asyncio.get_event_loop()
1250+
loop.set_exception_handler(_handle_exception)
12521251
asyncio.create_task(bar())
12531252
for _ in range(5):
12541253
print('Working')

0 commit comments

Comments
 (0)