File tree Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Original file line number Diff line number Diff line change @@ -1230,7 +1230,7 @@ queued for execution.
1230
1230
1231
1231
During development it is often best if untrapped exceptions stop the program
1232
1232
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:
1234
1234
``` python
1235
1235
import uasyncio as asyncio
1236
1236
import sys
@@ -1239,16 +1239,15 @@ def _handle_exception(loop, context):
1239
1239
print (' Global handler' )
1240
1240
sys.print_exception(context[" exception" ])
1241
1241
# 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
1246
1243
1247
1244
async def bar ():
1248
1245
await asyncio.sleep(0 )
1249
1246
1 / 0 # Crash
1250
1247
1251
1248
async def main ():
1249
+ loop = asyncio.get_event_loop()
1250
+ loop.set_exception_handler(_handle_exception)
1252
1251
asyncio.create_task(bar())
1253
1252
for _ in range (5 ):
1254
1253
print (' Working' )
You can’t perform that action at this time.
0 commit comments