dabeaz / curio

Good Curio!
Other
4.02k stars 241 forks source link

Avoid printing to stderr when exception is caught #224

Closed ariddell closed 7 years ago

ariddell commented 7 years ago

My expectation (from Python) is that when I catch an exception, I shouldn't see anything in stderr.

Is there any way to suppress the RuntimeError being written to stderr in the following case?

import curio

async def bad():
    raise RuntimeError('bad task')

async def go():
    async with curio.TaskGroup() as tg:
        task = await tg.spawn(bad)
        try:
            result = await task.join()
        except curio.TaskError as e:
            print('caught the exception', e.__cause__)

curio.run(go)

Thanks for curio! This is much easier to use than asyncio.

dabeaz commented 7 years ago

All output in Curio is routed through the logging module. So, one way to silence the output would be to configure logging to ignore it. There is also a debug flag to run that can silence it.

curio.run(go, debug=None)
ariddell commented 7 years ago

That does the trick!