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
Verbose TypeError for asyncio.ensure_future #74284
Comments
Despite the shy mention in the docs, it was not clear to me that the future returned from asyncio.run_coroutine_threadsafe is not compatible with asyncio.ensure_future (and other asyncio functions), and it took me a fair amount of frustration and source-code-digging to figure out what was going on. To avoid this confusion for other users, I think that a verbose TypeError warning when a concurrent.futures.Future object is passed into asyncio.ensure_future would be very helpful. |
|
Totally. But this wasn't immediately clear to me when using the API. A verbose error like this one would have made this behavior more clear to me. |
Well, it already raises a TypeError with a clear message -- this is how we tell the user that the argument type is not supported in Python. I don't think we need to specialize this code any further. Instead I'd suggest to try to improve asyncio documentation for |
This is more to my point: I found the TypeError message not clear at all. From my prospective, I was using a future object returned from an asyncio function to call another asyncio function, yet that function was telling me it could only use a future with it. Though I eventually figured out what was going on, I think that a more clear message at that moment would have been very helpful to me. And I think other users who benefit from this was well. A better warning/wording for the API would be helpful as well, but I don't think it fully suffices the problem. |
I understand, but this is the first time I see somebody tries to use Specializing error messages makes code more complex and adds to maintenance overhead, so we can't afford to make changes on first request. In cases like this we usually put the issue on hold to see if more people complain. |
Totally understandable. Some final thoughts:
Thanks for your time and insight, Yury! |
Yeah, I don't think we see enough reporting on bugs.python.org. I hope people will become more vocal :) I try to monitor what people say about asyncio on SO, Twitter and /r/python to get a better picture.
Feel free to suggest a better wording. |
I don't think your specialized error message adds anything. The the most common mistake, IMO, is going to be not realizing that run_coroutine_threadsafe don't return one of the acceptable types. So being told that concurrent.future.Future is not acceptable will add zero additional information. I think the only change that needs to be made is to make the existing message say 'asyncio.Future' instead of just 'Future'. |
I hear ya. New commit in the PR reverts the TypeError I added, and changes the original TypeError language to simply read "An asyncio.Future ..." instead of just "A Future ...". |
PR has been merged and backported to 3.5 and 3.6. |
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: