-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Clearer assertion error #84305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
https://discuss.python.org/t/assertionerror-asyncio-streams-in-drain-helper/3743/4 I recently came across this error, which I now know how to fix. I think the error can be clearer and I've a PR which I think does so. |
Do we really want this to be just an assert, or do we want to raise another type of exception? I think it's showing a real programming error that we wouldn't want to throw away with -O. |
IMO, we should look into converting this into an exception. Mistakenly having a task await StreamWriter.drain() at the same time as another is calling StreamWriter.write() does seem like a reasonable programming error that should preferably have an informative error message. Optimally, assertions shouldn't occur from normal programming errors in production. The tricky part is figuring out how to implement it properly. I'm not 100% certain that we can make any guarantees that when the _drain_waiter future hasn't been cancelled and not set to None that someone is mistakenly doing the above. It could potentially trigger from other errors. Either way though, I think just adding a message to the assert could end up being misleading if someone else encounters this in production for another reason. Instead, I think we could leave a comment there for now and in the long term figure out how to properly implement the exception or warning. We also need a reliable way to reproduce it, mainly for the purpose of writing a new test to ensure the exception is correctly triggered when someone makes the above programming error. |
How about we review Phil's PR, which adds a message to the assertion. And then we can keep this issue open to discuss converting the assertion to an exception. I think Phil's PR is an improvement. |
I don't see anything in the documentation of drain() that states that it cannot be called from multiple tasks. I'm also not sure why this assertion is necessary. If self._drain_waiter is already set, could the other task just await on it? |
I'm pretty sure this issue is a duplicate of bpo-issue29930. |
Duplicate of #74116 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: