summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/proactor_events.py
Commit message (Collapse)AuthorAgeFilesLines
* Issue #27136: Fix DNS static resolution; don't use it in getaddrinfoYury Selivanov2016-06-081-8/+1
| | | | Patch by A. Jesse Jiryu Davis
* Issue #27041: asyncio: Add loop.create_future methodYury Selivanov2016-05-161-1/+1
|
* asyncio: Don't log ConnectionAbortedErrorVictor Stinner2016-04-011-1/+1
| | | | | Issue #26509: In fatal error handlers, don't log ConnectionAbortedError which occur on Windows.
* asyncio: Skip getaddrinfo if host is already resolved.Yury Selivanov2015-12-171-2/+1
| | | | | | | | | | | | | getaddrinfo takes an exclusive lock on some platforms, causing clients to queue up waiting for the lock if many names are being resolved concurrently. Users may want to handle name resolution in their own code, for the sake of caching, using an alternate resolver, or to measure DNS duration separately from connection duration. Skip getaddrinfo if the "host" passed into create_connection is already resolved. See https://github.com/python/asyncio/pull/302 for details. Patch by A. Jesse Jiryu Davis.
* asyncio: Cleanup Future APIYury Selivanov2015-11-171-1/+2
| | | | See https://github.com/python/asyncio/pull/292 for details.
* asyncio: Add Transport.is_closing()Yury Selivanov2015-11-161-0/+3
| | | | See https://github.com/python/asyncio/pull/291 for details.
* asyncio: Sync with upstream (compat module)Yury Selivanov2015-08-041-2/+2
|
* asyncio: Only call _check_resolved_address() in debug modeVictor Stinner2015-02-041-1/+2
| | | | | | | | | | | | | | | | * _check_resolved_address() is implemented with getaddrinfo() which is slow * If available, use socket.inet_pton() instead of socket.getaddrinfo(), because it is much faster Microbenchmark (timeit) on Fedora 21 (Python 3.4, Linux 3.17, glibc 2.20) to validate the IPV4 address "127.0.0.1" or the IPv6 address "::1": * getaddrinfo() 10.4 usec per loop * inet_pton(): 0.285 usec per loop On glibc older than 2.14, getaddrinfo() always requests the list of all local IP addresses to the kernel (using a NETLINK socket). getaddrinfo() has other known issues, it's better to avoid it when it is possible.
* Issue #23243, asyncio: Emit a ResourceWarning when an event loop or a transportVictor Stinner2015-01-291-0/+11
| | | | is not explicitly closed. Close also explicitly transports in test_sslproto.
* asyncio: SSL transports now clear their reference to the waiterVictor Stinner2015-01-281-1/+1
| | | | | | | * Rephrase also the comment explaining why the waiter is not awaken immediatly. * SSLProtocol.eof_received() doesn't instanciate ConnectionResetError exception directly, it will be done by Future.set_exception(). The exception is not used if the waiter was cancelled or if there is no waiter.
* asyncio: Enhance BaseProactorEventLoop._loop_self_reading()Victor Stinner2015-01-211-3/+9
| | | | | | | | * Handle correctly CancelledError: just exit * On error, log the exception and exit Don't try to close the event loop, it is probably running and so it cannot be closed.
* asyncio: Fix _ProactorBasePipeTransport.close()Victor Stinner2015-01-151-1/+3
| | | | | | | Set the _read_fut attribute to None after cancelling it. This change should fix a race condition with _ProactorWritePipeTransport._pipe_closed().
* asyncio: Fix _ProactorBasePipeTransport.__repr__()Victor Stinner2015-01-151-3/+3
| | | | Check if the _sock attribute is None to check if the transport is closed.
* asyncio: sync with TulipVictor Stinner2015-01-141-0/+1
| | | | | | | | | | | | | | | | | | | | | | | * PipeHandle now uses None instead of -1 for a closed handle * Sort imports in windows_utils. * Fix test_events on Python older than 3.5. Skip SSL tests on the ProactorEventLoop if ssl.MemoryIO is missing * Fix BaseEventLoop._create_connection_transport(). Close the transport if the creation of the transport (if the waiter) gets an exception. * _ProactorBasePipeTransport now sets _sock to None when the transport is closed. * Fix BaseSubprocessTransport.close(). Ignore pipes for which the protocol is not set yet (still equal to None). * TestLoop.close() now calls the close() method of the parent class (BaseEventLoop). * Cleanup BaseSelectorEventLoop: create the protocol on a separated line for readability and ease debugging. * Fix BaseSubprocessTransport._kill_wait(). Set the _returncode attribute, so close() doesn't try to terminate the process. * Tests: explicitly close event loops and transports * UNIX pipe transports: add closed/closing in repr(). Add "closed" or "closing" state in the __repr__() method of _UnixReadPipeTransport and _UnixWritePipeTransport classes.
* Issue #22560: New SSL implementation based on ssl.MemoryBIOVictor Stinner2015-01-131-6/+25
| | | | | | | | | | | | | | | | | | | The new SSL implementation is based on the new ssl.MemoryBIO which is only available on Python 3.5. On Python 3.4 and older, the legacy SSL implementation (using SSL_write, SSL_read, etc.) is used. The proactor event loop only supports the new implementation. The new asyncio.sslproto module adds _SSLPipe, SSLProtocol and _SSLProtocolTransport classes. _SSLPipe allows to "wrap" or "unwrap" a socket (switch between cleartext and SSL/TLS). Patch written by Antoine Pitrou. sslproto.py is based on gruvi/ssl.py of the gruvi project written by Geert Jansen. This change adds SSL support to ProactorEventLoop on Python 3.5 and newer! It becomes also possible to implement STARTTTLS: switch a cleartext socket to SSL.
* Issue #22922: Fix ProactorEventLoop.close()Victor Stinner2015-01-131-1/+7
| | | | | Close the IocpProactor before closing the event loop. IocpProactor.close() can call loop.call_soon(), which is forbidden when the event loop is closed.
* asyncio: sync with TulipVictor Stinner2015-01-091-1/+2
| | | | | | | * Tulip issue 184: FlowControlMixin constructor now get the event loop if the loop parameter is not set. Add unit tests to ensure that constructor of StreamReader and StreamReaderProtocol classes get the event loop. * Remove outdated TODO/XXX
* Issue #22926: In debug mode, call_soon(), call_at() and call_later() methods ofVictor Stinner2014-12-261-4/+2
| | | | | | | | | | asyncio.BaseEventLoop now use the identifier of the current thread to ensure that they are called from the thread running the event loop. Before, the get_event_loop() method was used to check the thread, and no exception was raised when the thread had no event loop. Now the methods always raise an exception in debug mode when called from the wrong thread. It should help to notice misusage of the API.
* asyncio, tulip issue 202: Add unit test of pause/resume writing for proactorVictor Stinner2014-12-111-4/+0
| | | | socket transport
* Issue #22922: Fix ProactorEventLoop.close()Victor Stinner2014-12-051-1/+3
| | | | | Call _stop_accept_futures() before sestting the _closed attribute, otherwise call_soon() raises an error.
* asyncio: Move loop attribute to _FlowControlMixinVictor Stinner2014-11-051-2/+1
| | | | | | | | | Move the _loop attribute from the constructor of _SelectorTransport, _ProactorBasePipeTransport and _UnixWritePipeTransport classes to the constructor of the _FlowControlMixin class. Add also an assertion to explicit that the parent class must ensure that the loop is defined (not None)
* asyncio: enhance protocol representationVictor Stinner2014-10-121-1/+7
| | | | Add "closed" or "closing" to repr() of selector and proactor transports
* asyncio: sync with TulipVictor Stinner2014-08-251-11/+13
| | | | | | | | | | | | | | | | | | | | | | | * PipeServer.close() now cancels the "accept pipe" future which cancels the overlapped operation. * Fix _SelectorTransport.__repr__() if the transport was closed * Fix debug log in BaseEventLoop.create_connection(): get the socket object from the transport because SSL transport closes the old socket and creates a new SSL socket object. Remove also the _SelectorSslTransport._rawsock attribute: it contained the closed socket (not very useful) and it was not used. * Issue #22063: socket operations (sock_recv, sock_sendall, sock_connect, sock_accept) of the proactor event loop don't raise an exception in debug mode if the socket are in blocking mode. Overlapped operations also work on blocking sockets. * Fix unit tests in debug mode: mock a non-blocking socket for socket operations which now raise an exception if the socket is blocking. * _fatal_error() method of _UnixReadPipeTransport and _UnixWritePipeTransport now log all exceptions in debug mode * Don't log expected errors in unit tests * Tulip issue 200: _WaitHandleFuture._unregister_wait() now catchs and logs exceptions. * Tulip issue 200: Log errors in debug mode instead of simply ignoring them.
* Close #22063: socket operations (socket,recv, sock_sendall, sock_connect,Victor Stinner2014-07-291-0/+8
| | | | | sock_accept) now raise an exception in debug mode if sockets are in blocking mode.
* asyncio: sync with TulipVictor Stinner2014-07-251-6/+2
| | | | | | | | | | | | * Fix _WaitHandleFuture.cancel(): return the result of the parent cancel() method. * _OverlappedFuture.cancel() now clears its reference to the overlapped object. Make also the _OverlappedFuture.ov attribute private. * Check if _WaitHandleFuture completed before unregistering it in the callback. Add also _WaitHandleFuture._poll() and repr(_WaitHandleFuture). * _WaitHandleFuture now unregisters its wait handler if WaitForSingleObject() raises an exception. * _OverlappedFuture.set_exception() now cancels the overlapped operation.
* Python issue #21645, Tulip issue 192: Rewrite signal handlingVictor Stinner2014-07-171-1/+1
| | | | | | | | | | | | | | | | | | | Since Python 3.3, the C signal handler writes the signal number into the wakeup file descriptor and then schedules the Python call using Py_AddPendingCall(). asyncio uses the wakeup file descriptor to wake up the event loop, and relies on Py_AddPendingCall() to schedule the final callback with call_soon(). If the C signal handler is called in a thread different than the thread of the event loop, the loop is awaken but Py_AddPendingCall() was not called yet. In this case, the event loop has nothing to do and go to sleep again. Py_AddPendingCall() is called while the event loop is sleeping again and so the final callback is not scheduled immediatly. This patch changes how asyncio handles signals. Instead of relying on Py_AddPendingCall() and the wakeup file descriptor, asyncio now only relies on the wakeup file descriptor. asyncio reads signal numbers from the wakeup file descriptor to call its signal handler.
* asyncio: sync with TulipVictor Stinner2014-07-121-3/+33
| | | | | | | | | | | | | | | | | | | * Tulip issue #183: log socket events in debug mode - Log most important socket events: socket connected, new client, connection reset or closed by peer (EOF), etc. - Log time elapsed in DNS resolution (getaddrinfo) - Log pause/resume reading - Log time of SSL handshake - Log SSL handshake errors - Add a __repr__() method to many classes * Fix ProactorEventLoop() in debug mode. ProactorEventLoop._make_self_pipe() doesn't call call_soon() directly because it checks for the current loop which fails, because the method is called to build the event loop. * Cleanup _ProactorReadPipeTransport constructor. Not need to set again _read_fut attribute to None, it is already done in the base class.
* asyncio, Tulip issue 180: Make Server attributes and methods privateVictor Stinner2014-07-111-2/+2
| | | | | | | - loop, waiters and active_count attributes are now private - attach(), detach() and wakeup() methods are now private The sockets attribute remains public.
* asyncion, Tulip issue 181: BaseEventLoop.create_datagram_endpoint() now waitsVictor Stinner2014-07-081-0/+1
| | | | | until protocol.connection_made() has been called. Document also why transport constructors use a waiter.
* asyncio: sync with TulipVictor Stinner2014-07-071-1/+1
| | | | | Backout the "Tulip issue 181: Faster create_connection()" changeset, it was a mistake.
* asyncio: sync with TulipVictor Stinner2014-07-071-1/+1
| | | | | | | | - Tulip issue #181: Faster create_connection(). Call directly waiter.set_result() in the constructor of _ProactorBasePipeTransport and _SelectorSocketTransport, instead of using of delaying the call with call_soon(). - Cleanup iscoroutine()
* Closes #21886, #21447: Fix a race condition in asyncio when setting the resultVictor Stinner2014-07-051-1/+1
| | | | | of a Future with call_soon(). Add an helper, a private method, to set the result only if the future was not cancelled.
* asyncio, Tulip issue 171: BaseEventLoop.close() now raises an exception if theVictor Stinner2014-06-221-1/+1
| | | | | event loop is running. You must first stop the event loop and then wait until it stopped, before closing it.
* Issue #21326: Add a new is_closed() method to asyncio.BaseEventLoopVictor Stinner2014-06-101-8/+15
| | | | | | | | | | | Add BaseEventLoop._closed attribute and use it to check if the event loop was closed or not, instead of checking different attributes in each subclass of BaseEventLoop. run_forever() and run_until_complete() methods now raise a RuntimeError('Event loop is closed') exception if the event loop was closed. BaseProactorEventLoop.close() now also cancels "accept futures".
* asyncio: Fix _ProactorWritePipeTransport._pipe_closed()Victor Stinner2014-02-201-1/+1
| | | | The "exc" variable was not defined, pass a BrokenPipeError exception instead.
* asyncio, Tulip issue 139: Improve error messages on "fatal errors"Victor Stinner2014-02-191-5/+5
| | | | | Mention if the error was caused by a read or a write, and be more specific on the object (ex: "pipe transport" instead of "transport").
* asyncio.transports: Make _ProactorBasePipeTransport use _FlowControlMixinYury Selivanov2014-02-181-53/+2
|
* asyncio: New error handling API. Issue #20681.Yury Selivanov2014-02-181-7/+26
|
* ayncio, Tulip issue 129: BaseEventLoop.sock_connect() now raises an error ifVictor Stinner2014-02-131-1/+8
| | | | | the address is not resolved (hostname instead of an IP address) for AF_INET and AF_INET6 address families.
* Issue #20505: Remove resolution and _granularity from selectors and asyncioVictor Stinner2014-02-071-1/+0
| | | | | * Remove selectors.BaseSelector.resolution attribute * Remove asyncio.BaseEventLoop._granularity attribute
* asyncio: Fix _ProactorWritePipeTransport._pipe_closed()Victor Stinner2014-02-041-1/+4
| | | | | Do nothing if the pipe is already closed. _loop_writing() may call _force_close() when it gets ConnectionResetError.
* Issue #20400: Merge Tulip into Python: add the new asyncio.subprocess moduleVictor Stinner2014-02-011-13/+21
| | | | | | | | | | | | | | | | | | | | * Add a new asyncio.subprocess module * Add new create_subprocess_exec() and create_subprocess_shell() functions * The new asyncio.subprocess.SubprocessStreamProtocol creates stream readers for stdout and stderr and a stream writer for stdin. * The new asyncio.subprocess.Process class offers an API close to the subprocess.Popen class: - pid, returncode, stdin, stdout and stderr attributes - communicate(), wait(), send_signal(), terminate() and kill() methods * Remove STDIN (0), STDOUT (1) and STDERR (2) constants from base_subprocess and unix_events, to not be confused with the symbols with the same name of subprocess and asyncio.subprocess modules * _ProactorBasePipeTransport.get_write_buffer_size() now counts also the size of the pending write * _ProactorBaseWritePipeTransport._loop_writing() may now pause the protocol if the write buffer size is greater than the high water mark (64 KB by default)
* Issue #20455: Add a resolution attribute to IocpProactor (1 ms)Victor Stinner2014-01-311-0/+1
|
* Issue #20455: asyncio: write a new write pipe transport class for proactor (onVictor Stinner2014-01-311-12/+26
| | | | | | | Windows) instead of using the "duplex" pipe transport. The new class uses a simpler overlapped read to be notified when the pipe is closed. So the protocol doesn't need to implement eof_received(): connection_lost() is called instead. _UnixWritePipeTransport has the same approach.
* asyncio: _fatal_error() of _UnixWritePipeTransport and ↵Victor Stinner2014-01-291-1/+2
| | | | | | _ProactorBasePipeTransport shouldn't log BrokenPipeError nor ConnectionResetError. (Same behaviour as _SelectorTransport._fatal_error().)
* Update asyncio from the Tulip projectVictor Stinner2014-01-251-0/+2
| | | | | | | | | | | | | | | | Major changes: - StreamReader.readexactly() now raises an IncompleteReadError if the end of stream is reached before we received enough bytes, instead of returning less bytes than requested. - Unit tests use the main asyncio module instead of submodules like events - _UnixWritePipeTransport now also supports character devices, as _UnixReadPipeTransport. Patch written by Jonathan Slenders. - Export more symbols: BaseEventLoop, BaseProactorEventLoop, BaseSelectorEventLoop, Queue and Queue sublasses, Empty, Full
* Cleanup properly proactor event loopVictor Stinner2014-01-101-0/+10
| | | | | | | | | * store the "self reading" future when the "self pipe" is closed (when the event loop is closed) * store "accept" futures to cancel them when we stop serving * close the "accept socket" if the "accept future" is cancelled Fix many warnings which can be seen when unit tests are run in verbose mode.
* asyncio: Write flow control for proactor event loop.Guido van Rossum2013-12-041-17/+99
|
* asyncio: Add support for running subprocesses on Windows with the IOCP event ↵Guido van Rossum2013-10-301-2/+9
| | | | loop (Richard Oudkerk).
* Issue #19299: fix refleak test failures in test_asyncioAntoine Pitrou2013-10-191-0/+1
|