cpython: 2c9d5f32f6c5 (original) (raw)

--- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -2,8 +2,8 @@ .. _asyncio-event-loop: -Event loops -=========== +Base Event Loop +=============== The event loop is the central execution device provided by :mod:asyncio. It provides multiple facilities, amongst which: @@ -18,78 +18,9 @@ It provides multiple facilities, amongst

-.. function:: set_event_loop(loop) -

-.. function:: new_event_loop() +.. class:: BaseEventLoop

-Event loop policy interface ---------------------------- - -An event loop policy must implement the following interface: - -.. class:: AbstractEventLoopPolicy -

-Access to the global loop policy --------------------------------- - -.. function:: get_event_loop_policy() -

-.. function:: set_event_loop_policy(policy) -

Run an event loop ----------------- @@ -375,7 +306,6 @@ Creating listening connections Availability: UNIX. - Watch file descriptors ---------------------- @@ -624,7 +554,6 @@ Debug mode The :ref:debug mode of asyncio <asyncio-debug-mode>. - Server ------ @@ -652,7 +581,8 @@ Handle .. method:: cancel()

+ .. _asyncio-hello-world-callback:

copy from Doc/library/asyncio-eventloop.rst copy to Doc/library/asyncio-eventloops.rst --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloops.rst @@ -1,40 +1,8 @@ .. currentmodule:: asyncio -.. _asyncio-event-loop: - Event loops =========== -The event loop is the central execution device provided by :mod:asyncio. -It provides multiple facilities, amongst which: - -* Registering, executing and cancelling delayed calls (timeouts). - -* Creating client and server :ref:transports <asyncio-transport> for various

+.. class:: ProactorEventLoop +

+ +Example to use a :class:ProactorEventLoop on Windows:: +

+

+ + +Platform support +---------------- + +The :mod:asyncio module has been designed to be portable, but each platform +still has subtle differences and may not support all :mod:asyncio features. + +Windows +^^^^^^^ + +Common limits of Windows event loops: + +- :meth:~BaseEventLoop.create_unix_server and

+

+ + +Event loop policies and the default policy +------------------------------------------ + +Event loop management is abstracted with a policy pattern, to provide maximal +flexibility for custom platforms and frameworks. Throughout the execution of a +process, a single global policy object manages the event loops available to the +process based on the calling context. A policy is an object implementing the +:class:AbstractEventLoopPolicy interface. + +For most users of :mod:asyncio, policies never have to be dealt with +explicitly, since the default global policy is sufficient. + +The default policy defines context as the current thread, and manages an event +loop per thread that interacts with :mod:asyncio. The module-level functions +:func:get_event_loop and :func:set_event_loop provide convenient access to +event loops managed by the default policy. + Event loop policy interface --------------------------- @@ -91,618 +174,3 @@ Access to the global loop policy Set the current event loop policy. If policy is None, the default policy is restored. -Run an event loop ------------------ - -.. method:: BaseEventLoop.run_forever() -

-.. method:: BaseEventLoop.run_until_complete(future) -

-.. method:: BaseEventLoop.is_running() -

-.. method:: BaseEventLoop.stop() -

-.. method:: BaseEventLoop.is_closed() -

-.. method:: BaseEventLoop.close() -

- -Calls ------ - -.. method:: BaseEventLoop.call_soon(callback, *args) -

-.. method:: BaseEventLoop.call_soon_threadsafe(callback, *args) -

- -.. _asyncio-delayed-calls: - -Delayed calls -------------- - -The event loop has its own internal clock for computing timeouts. -Which clock is used depends on the (platform-specific) event loop -implementation; ideally it is a monotonic clock. This will generally be -a different clock than :func:time.time. - -.. note:: -

- -.. method:: BaseEventLoop.call_later(delay, callback, *args) -

-.. method:: BaseEventLoop.call_at(when, callback, *args) -

-.. method:: BaseEventLoop.time() -

-.. seealso:: -

- -Coroutines ----------- - -.. method:: BaseEventLoop.create_task(coro) -

-

- -Creating connections --------------------- - -.. method:: BaseEventLoop.create_connection(protocol_factory, host=None, port=None, *, ssl=None, family=0, proto=0, flags=0, sock=None, local_addr=None, server_hostname=None) -

-

-

-

-

-

-

-

-

-

-

-

- - -.. method:: BaseEventLoop.create_datagram_endpoint(protocol_factory, local_addr=None, remote_addr=None, *, family=0, proto=0, flags=0) -

- -.. method:: BaseEventLoop.create_unix_connection(protocol_factory, path, *, ssl=None, sock=None, server_hostname=None) -

- -Creating listening connections ------------------------------- - -.. method:: BaseEventLoop.create_server(protocol_factory, host=None, port=None, *, family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE, sock=None, backlog=100, ssl=None, reuse_address=None) -

- - -.. method:: BaseEventLoop.create_unix_server(protocol_factory, path=None, *, sock=None, backlog=100, ssl=None) -

- - -Watch file descriptors ----------------------- - -.. method:: BaseEventLoop.add_reader(fd, callback, *args) -

-.. method:: BaseEventLoop.remove_reader(fd) -

-.. method:: BaseEventLoop.add_writer(fd, callback, *args) -

-.. method:: BaseEventLoop.remove_writer(fd) -

- -Low-level socket operations ---------------------------- - -.. method:: BaseEventLoop.sock_recv(sock, nbytes) -

- -.. method:: BaseEventLoop.sock_sendall(sock, data) -

- -.. method:: BaseEventLoop.sock_connect(sock, address) -

- - -.. method:: BaseEventLoop.sock_accept(sock) -

- - -Resolve host name ------------------ - -.. method:: BaseEventLoop.getaddrinfo(host, port, *, family=0, type=0, proto=0, flags=0) -

-.. method:: BaseEventLoop.getnameinfo(sockaddr, flags=0) -

- -Connect pipes -------------- - -.. method:: BaseEventLoop.connect_read_pipe(protocol_factory, pipe) -

-.. method:: BaseEventLoop.connect_write_pipe(protocol_factory, pipe) -

-.. seealso:: -

- -UNIX signals ------------- - -Availability: UNIX only. - -.. method:: BaseEventLoop.add_signal_handler(signum, callback, *args) -

-.. method:: BaseEventLoop.remove_signal_handler(sig) -

-.. seealso:: -

- -Executor --------- - -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). - -.. method:: BaseEventLoop.run_in_executor(executor, callback, *args) -

-.. method:: BaseEventLoop.set_default_executor(executor) -

- -Error Handling API ------------------- - -Allows to customize how exceptions are handled in the event loop. - -.. method:: BaseEventLoop.set_exception_handler(handler) -

-.. method:: BaseEventLoop.default_exception_handler(context) -

-.. method:: BaseEventLoop.call_exception_handler(context) -

- -Debug mode ----------- - -.. method:: BaseEventLoop.get_debug() -

-.. method:: BaseEventLoop.set_debug(enabled: bool) -

-.. seealso:: -

- -Server ------- - -.. class:: AbstractServer -

-

- - -Handle ------- - -.. class:: Handle -

- -.. _asyncio-hello-world-callback: - -Example: Hello World (callback) -------------------------------- - -Print Hello World every two seconds, using a callback:: -

-

-

- -.. seealso:: -

- -Example: Set signal handlers for SIGINT and SIGTERM ---------------------------------------------------- - -Register handlers for signals :py:data:SIGINT and :py:data:SIGTERM:: -

-

-

-

-

--- a/Doc/library/asyncio-subprocess.rst +++ b/Doc/library/asyncio-subprocess.rst @@ -3,18 +3,18 @@ Subprocess ========== -Operating system support ------------------------- +Windows event loop +------------------ -On Windows, the default event loop uses :class:selectors.SelectSelector -which only supports sockets. The :class:ProactorEventLoop should be used to -support subprocesses. However, the latter does not support SSL. +On Windows, the default event loop is :class:SelectorEventLoop which does not +support subprocesses. :class:ProactorEventLoop should be used instead. +Example to use it on Windows:: -On Mac OS X older than 10.9 (Mavericks), :class:selectors.KqueueSelector -does not support character devices like PTY, whereas it is used by the -default event loop. The :class:SelectorEventLoop can be used with -:class:SelectSelector or :class:PollSelector to handle character -devices on Mac OS X 10.6 (Snow Leopard) and later.

+

Create a subprocess: high-level API using Process

--- a/Doc/library/asyncio.rst +++ b/Doc/library/asyncio.rst @@ -45,6 +45,7 @@ Table of content: :maxdepth: 3 asyncio-eventloop.rst