Coroutine sink exceptions are not caught
See original GitHub issueIt appears that if you use a coroutine as a sink and it has an unhandled exception, even with catch=True
specified in add()
, the exception is not caught, and you will get a Task exception was never retrieved
error on stderr from asyncio: https://docs.python.org/3/library/asyncio-dev.html#detect-never-retrieved-exceptions
import asyncio
from loguru import logger
async def sink(msg):
raise Exception("oh no")
async def main():
logger.add(sink, catch=True)
logger.info("hello world")
asyncio.run(main())
2020-03-23 12:31:58.236 | INFO | main:main:3 - hello world Task exception was never retrieved future: <Task finished name=‘Task-2’ coro=<sink() done, defined at <stdin>:1> exception=Exception(‘oh no’)> Traceback (most recent call last): File “<stdin>”, line 2, in sink Exception: oh no
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Exceptions in coroutines. Cancellation and Exceptions in…
When a coroutine fails with an exception, it will propagate said exception up to its parent! Then, the parent will 1) cancel the...
Read more >Exception not being caught in Coroutines - Stack Overflow
Trying with CoroutineExceptionHandler can be workaround for handling exceptions inside coroutines. CoroutineExceptionHandler context element ...
Read more >Exception Handling in Kotlin Coroutines EXPLAINED - YouTube
Get the full 15+ hour-long Course "Kotlin Coroutines and Flow for Android Development" with a nice discount here: ...
Read more >C++ boost::coroutine::exception - CPPSECRETS
Name Views Likes
C++ boost::utility::noncopyable 284 0
C++ boost::coroutine::passing values to Coroutine 231 6
C++ boost::intrusive::pop_back() 255 0
Read more >Chapter 51. Boost.Coroutine - The Boost C++ Libraries
While source in main() represents the coroutine cooperative() , sink in ... be caught. Thus, exceptions are no different than with regular function...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed in next version. 😃
Great, so we agree on how this should behave. 👍
I’m a little worried about the callback overhead but I don’t see any other simple solution.