Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bec2372

Browse files
authored
bpo-32327: Revert loop.run_in_executor behaviour: return a Future. (#5392)
I've run some tests on 3.7 asyncio and it appears that too many things assume that run_in_executor returns a Future.
1 parent a4d0001 commit bec2372

4 files changed

Lines changed: 14 additions & 12 deletions

File tree

Doc/library/asyncio-eventloop.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,12 @@ Resolve host name
782782
This method is a :ref:`coroutine <coroutine>`, similar to
783783
:meth:`socket.getnameinfo` function but non-blocking.
784784

785+
.. versionchanged:: 3.7
786+
Both *getaddrinfo* and *getnameinfo* methods were always documented
787+
to return a coroutine, but prior to Python 3.7 they were, in fact,
788+
returning :class:`asyncio.Future` objects. Starting with Python 3.7
789+
both methods are coroutines.
790+
785791

786792
Connect pipes
787793
-------------
@@ -852,7 +858,7 @@ Call a function in an :class:`~concurrent.futures.Executor` (pool of threads or
852858
pool of processes). By default, an event loop uses a thread pool executor
853859
(:class:`~concurrent.futures.ThreadPoolExecutor`).
854860

855-
.. coroutinemethod:: AbstractEventLoop.run_in_executor(executor, func, \*args)
861+
.. method:: AbstractEventLoop.run_in_executor(executor, func, \*args)
856862

857863
Arrange for a *func* to be called in the specified executor.
858864

@@ -862,18 +868,15 @@ pool of processes). By default, an event loop uses a thread pool executor
862868
:ref:`Use functools.partial to pass keywords to the *func*
863869
<asyncio-pass-keywords>`.
864870

871+
This method returns a :class:`asyncio.Future` object.
872+
865873
.. versionchanged:: 3.5.3
866874
:meth:`BaseEventLoop.run_in_executor` no longer configures the
867875
``max_workers`` of the thread pool executor it creates, instead
868876
leaving it up to the thread pool executor
869877
(:class:`~concurrent.futures.ThreadPoolExecutor`) to set the
870878
default.
871879

872-
.. versionchanged:: 3.7
873-
Even though the method was always documented as a coroutine
874-
method, before Python 3.7 it returned a :class:`Future`.
875-
Since Python 3.7, this is an ``async def`` method.
876-
877880
.. method:: AbstractEventLoop.set_default_executor(executor)
878881

879882
Set the default executor used by :meth:`run_in_executor`.

Lib/asyncio/base_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ def call_soon_threadsafe(self, callback, *args, context=None):
721721
self._write_to_self()
722722
return handle
723723

724-
async def run_in_executor(self, executor, func, *args):
724+
def run_in_executor(self, executor, func, *args):
725725
self._check_closed()
726726
if self._debug:
727727
self._check_callback(func, 'run_in_executor')
@@ -730,7 +730,7 @@ async def run_in_executor(self, executor, func, *args):
730730
if executor is None:
731731
executor = concurrent.futures.ThreadPoolExecutor()
732732
self._default_executor = executor
733-
return await futures.wrap_future(
733+
return futures.wrap_future(
734734
executor.submit(func, *args), loop=self)
735735

736736
def set_default_executor(self, executor):

Lib/test/test_asyncio/test_tasks.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,9 +2999,8 @@ def test_run_coroutine_threadsafe_task_factory_exception(self):
29992999
def task_factory(loop, coro):
30003000
raise NameError
30013001

3002-
run = self.loop.create_task(
3003-
self.loop.run_in_executor(
3004-
None, lambda: self.target(advance_coro=True)))
3002+
run = self.loop.run_in_executor(
3003+
None, lambda: self.target(advance_coro=True))
30053004

30063005
# Set exception handler
30073006
callback = test_utils.MockCallback()

Misc/NEWS.d/3.7.0a4.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ Implement asyncio.create_task(coro) shortcut
426426
427427
Convert asyncio functions that were documented as coroutines to coroutines.
428428
Affected functions: loop.sock_sendall, loop.sock_recv, loop.sock_accept,
429-
loop.run_in_executor, loop.getaddrinfo, loop.getnameinfo.
429+
loop.getaddrinfo, loop.getnameinfo.
430430

431431
..
432432

0 commit comments

Comments
 (0)