bpo-36916: Swallow unhandled exception by asvetlov · Pull Request #13313 · python/cpython
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a special case here.
Basically, there are two ways to call write() now:
- Legacy
writer.write(b'data') - Recommended
await writer.write(b'data')
For the second case, an exception raised by nested writer.drain() call is propagated to user.
The first case ignores the exception from nested writer.drain() call, allowing existing code to work in a backward compatible way.
A subsequent call to drain() raises the exception again, like in the following snippet:
writer.write(b'data') # exception is swallowed
await writer.drain() # previous exception is raised if any
Sorry for such a tricky code.
Ideally, we should make writer.write() a coroutine from the very beginning.
Proposed workaround is a strategy to keep backward compatibility and provide a smooth transition path.