This repository was archived by the owner on Nov 23, 2017. It is now read-only.
loop.run_in_executor should be a coroutine #306
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since base_events.BaseEventLoop.run_in_executor returns a Future object, a caller can call it with yield from/await. However, the result of the call is not a coroutine since asyncio.iscoroutine(loop.run_in_executor(...)) returns False.
It matters when one wants to use run_in_executor() in a task, such as:
loop.create_task(loop.run_in_executor(...))
In this case, an exception is raised immediatly (AssertionError), while the task is effectively running in the executor.
This patch propose to make loop.run_in_executor() be an actual coroutine function (and be tested).
I believe that returning a Future and document the function as a coroutine used to be done quite often, maybe this should be fixed elsewhere too.
An alternative solution would be to change the documentation, explain why it can not be used with loop.create_task() and should be used with loop.ensure_future() instead.