]> granicus.if.org Git - python/commitdiff
bpo-32327: Revert loop.run_in_executor behaviour: return a Future. (#5392)
authorYury Selivanov <yury@magic.io>
Sun, 28 Jan 2018 19:09:40 +0000 (14:09 -0500)
committerGitHub <noreply@github.com>
Sun, 28 Jan 2018 19:09:40 +0000 (14:09 -0500)
I've run some tests on 3.7 asyncio and it appears that too many
things assume that run_in_executor returns a Future.

Doc/library/asyncio-eventloop.rst
Lib/asyncio/base_events.py
Lib/test/test_asyncio/test_tasks.py
Misc/NEWS.d/3.7.0a4.rst

index 78ae18391f73cd0baeb1c42f6dece876b7be8946..5f915c5c43921ad571d3f731890f5498c02305c6 100644 (file)
@@ -782,6 +782,12 @@ Resolve host name
    This method is a :ref:`coroutine <coroutine>`, similar to
    :meth:`socket.getnameinfo` function but non-blocking.
 
+.. versionchanged:: 3.7
+   Both *getaddrinfo* and *getnameinfo* methods were always documented
+   to return a coroutine, but prior to Python 3.7 they were, in fact,
+   returning :class:`asyncio.Future` objects.  Starting with Python 3.7
+   both methods are coroutines.
+
 
 Connect pipes
 -------------
@@ -852,7 +858,7 @@ Call a function in an :class:`~concurrent.futures.Executor` (pool of threads or
 pool of processes). By default, an event loop uses a thread pool executor
 (:class:`~concurrent.futures.ThreadPoolExecutor`).
 
-.. coroutinemethod:: AbstractEventLoop.run_in_executor(executor, func, \*args)
+.. method:: AbstractEventLoop.run_in_executor(executor, func, \*args)
 
    Arrange for a *func* to be called in the specified executor.
 
@@ -862,6 +868,8 @@ pool of processes). By default, an event loop uses a thread pool executor
    :ref:`Use functools.partial to pass keywords to the *func*
    <asyncio-pass-keywords>`.
 
+   This method returns a :class:`asyncio.Future` object.
+
    .. versionchanged:: 3.5.3
       :meth:`BaseEventLoop.run_in_executor` no longer configures the
       ``max_workers`` of the thread pool executor it creates, instead
@@ -869,11 +877,6 @@ pool of processes). By default, an event loop uses a thread pool executor
       (:class:`~concurrent.futures.ThreadPoolExecutor`) to set the
       default.
 
-   .. versionchanged:: 3.7
-      Even though the method was always documented as a coroutine
-      method, before Python 3.7 it returned a :class:`Future`.
-      Since Python 3.7, this is an ``async def`` method.
-
 .. method:: AbstractEventLoop.set_default_executor(executor)
 
    Set the default executor used by :meth:`run_in_executor`.
index 7442bf28b03525506d69541dc2452f718d0fa9db..09eb440b0ef7af86f50171cf462e5f6cb0f3a0c7 100644 (file)
@@ -721,7 +721,7 @@ class BaseEventLoop(events.AbstractEventLoop):
         self._write_to_self()
         return handle
 
-    async def run_in_executor(self, executor, func, *args):
+    def run_in_executor(self, executor, func, *args):
         self._check_closed()
         if self._debug:
             self._check_callback(func, 'run_in_executor')
@@ -730,7 +730,7 @@ class BaseEventLoop(events.AbstractEventLoop):
             if executor is None:
                 executor = concurrent.futures.ThreadPoolExecutor()
                 self._default_executor = executor
-        return await futures.wrap_future(
+        return futures.wrap_future(
             executor.submit(func, *args), loop=self)
 
     def set_default_executor(self, executor):
index 822338f932e72a9836a46d0f6fe14f5b95c50391..19cf1e667fc4be250ae3423dfda4651d8a3efdc1 100644 (file)
@@ -2999,9 +2999,8 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
         def task_factory(loop, coro):
             raise NameError
 
-        run = self.loop.create_task(
-            self.loop.run_in_executor(
-                None, lambda: self.target(advance_coro=True)))
+        run = self.loop.run_in_executor(
+            None, lambda: self.target(advance_coro=True))
 
         # Set exception handler
         callback = test_utils.MockCallback()
index a6322ed405bac381b9c37edfe558a445c5d18724..5c3da97fa9d9d88413753976134cc78472374663 100644 (file)
@@ -426,7 +426,7 @@ Implement asyncio.create_task(coro) shortcut
 
 Convert asyncio functions that were documented as coroutines to coroutines.
 Affected functions: loop.sock_sendall, loop.sock_recv, loop.sock_accept,
-loop.run_in_executor, loop.getaddrinfo, loop.getnameinfo.
+loop.getaddrinfo, loop.getnameinfo.
 
 ..