summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
Commit message (Collapse)AuthorAgeFilesLines
* asyncio, Tulip issue 205: Fix a race condition in ↵Victor Stinner2014-08-311-13/+31
| | | | | | | | | | | | | | | | | | | | | | BaseSelectorEventLoop.sock_connect() There is a race condition in create_connection() used with wait_for() to have a timeout. sock_connect() registers the file descriptor of the socket to be notified of write event (if connect() raises BlockingIOError). When create_connection() is cancelled with a TimeoutError, sock_connect() coroutine gets the exception, but it doesn't unregister the file descriptor for write event. create_connection() gets the TimeoutError and closes the socket. If you call again create_connection(), the new socket will likely gets the same file descriptor, which is still registered in the selector. When sock_connect() calls add_writer(), it tries to modify the entry instead of creating a new one. This issue was originally reported in the Trollius project, but the bug comes from Tulip in fact (Trollius is based on Tulip): https://bitbucket.org/enovance/trollius/issue/15/after-timeouterror-on-wait_for This change fixes the race condition. It also makes sock_connect() more reliable (and portable) is sock.connect() raises an InterruptedError.
* asyncio, Tulip issue 201: Fix a race condition in wait_for()Victor Stinner2014-08-281-6/+9
| | | | | | Don't raise a TimeoutError if we reached the timeout and the future completed in the same iteration of the event loop. A side effect of the bug is that Queue.get() looses items.
* asyncio, tulip issue 203: Add _FlowControlMixin.get_write_buffer_limits() methodVictor Stinner2014-08-251-0/+3
|
* asyncio: sync with TulipVictor Stinner2014-08-256-35/+78
| | | | | | | | | | | | | | | | | | | | | | | * 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-292-0/+16
| | | | | sock_accept) now raise an exception in debug mode if sockets are in blocking mode.
* asyncio: Use the new os.set_blocking() function of Python 3.5 if availableVictor Stinner2014-07-291-4/+8
|
* asyncio: sync with TulipVictor Stinner2014-07-294-64/+88
| | | | | | | | | | | | | | | | | | | | | | | | * _WaitHandleFuture.cancel() now notify IocpProactor through the overlapped object that the wait was cancelled. * Optimize IocpProactor.wait_for_handle() gets the result if the wait is signaled immediatly. * Enhance representation of Future and Future subclasses - Add "created at filename:lineno" in the representation - Add Future._repr_info() method which can be more easily overriden than Future.__repr__(). It should now be more easy to enhance Future representation without having to modify each subclass. For example, _OverlappedFuture and _WaitHandleFuture get the new "created at" information. - Use reprlib to format Future result, and function arguments when formatting a callback, to limit the length of the representation. * Fix repr(_WaitHandleFuture) * _WaitHandleFuture and _OverlappedFuture: hide frames of internal calls in the source traceback. * Cleanup ProactorIocp._poll(): set the timeout to 0 after the first call to GetQueuedCompletionStatus() * test_locks: close the temporary event loop and check the condition lock * Remove workaround in test_futures, no more needed
* asyncio, tulip issue 196: ProactorIocp._register() now registers the overlappedVictor Stinner2014-07-271-15/+38
| | | | | | | | | | | | | | | | in the _cache dictionary, even if we already got the result. We need to keep a reference to the overlapped object, otherwise the memory may be reused and GetQueuedCompletionStatus() may use random bytes and behaves badly. There is still a hack for ConnectNamedPipe(): the overlapped object is not register into _cache if the overlapped object completed directly. Log also an error in debug mode in ProactorIocp._loop() if we get an unexpected event. Add a protection in ProactorIocp.close() to avoid blocking, even if it should not happen. I still don't understand exactly why some the completion of some overlapped objects are not notified.
* Accept optional lock object in Condition ctor (tulip issue #198)Andrew Svetlov2014-07-261-3/+6
|
* Tulip issue 196: _OverlappedFuture.set_result() now clears its reference to theVictor Stinner2014-07-251-5/+11
| | | | | overlapped object. IocpProactor._poll() now also ignores false alarms: GetQueuedCompletionStatus() returns the overlapped but it is still pending.
* asyncio: sync with TulipVictor Stinner2014-07-252-1/+9
| | | | | | | | * Tulip issue #196: IocpProactor._poll() clears the reference to the overlapped operation when the operation is done. It would be better to clear the reference in a new _OverlappedFuture.set_result() method, but it cannot be done yet because of a weird bug. * BaseSelectorEventLoop._write_to_self() now logs errors in debug mode.
* asyncio: sync with TulipVictor Stinner2014-07-252-27/+52
| | | | | | | | | | | | * 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.
* asyncio: sync with TulipVictor Stinner2014-07-241-20/+46
| | | | | | | | | | | | | | | | | | | | | | Improve stability of the proactor event loop, especially operations on overlapped objects: * Tulip issue 195: Don't call UnregisterWait() twice if a _WaitHandleFuture is cancelled twice to fix a crash. * IocpProactor.close(): cancel futures to cancel overlapped operations, instead of cancelling directly overlapped operations. Future objects may not call ov.cancel() if the future was cancelled or if the overlapped was already cancelled. The cancel() method of the future may also catch exceptions. Log also errors on cancellation. * tests: rename "f" to "fut" * Add a __repr__() method to IocpProactor * Add a destructor to IocpProactor which closes it * _OverlappedFuture.cancel() doesn't cancel the overlapped anymore if it is done: if it is already cancelled or completed. Log also an error if the cancellation failed. * Add the address of the overlapped object in repr(_OverlappedFuture) * _OverlappedFuture truncates the source traceback to hide the call to the parent constructor (useless in debug).
* Issue #20055: Fix BaseEventLoop.stop() docstring, incomplete sentence.Victor Stinner2014-07-241-3/+3
| | | | Patch written by Saimadhav Heblikar.
* asyncio: sync with TulipVictor Stinner2014-07-231-3/+3
| | | | | * Tulip issue 194: Don't use sys.getrefcount() in unit tests * signal.set_wakeup_fd() can now raise an OSError on Python 3.5
* asyncio, tulip issue 193: Convert StreamWriter.drain() to a classic coroutineVictor Stinner2014-07-221-19/+18
| | | | | Replace also _make_drain_waiter() function with a classic _drain_helper() coroutine.
* Fix asyncio.__all__: export also unix_events and windows_events symbolsVictor Stinner2014-07-181-6/+7
| | | | | For example, on Windows, it was not possible to get ProactorEventLoop or DefaultEventLoopPolicy using "from asyncio import *".
* Python issue #21645, Tulip issue 192: Rewrite signal handlingVictor Stinner2014-07-173-4/+24
| | | | | | | | | | | | | | | | | | | 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, tulip issue 190: Process.communicate() now ignoresVictor Stinner2014-07-171-5/+7
| | | | ConnectionResetError too
* asyncio, tulip issue 190: Process.communicate() must ignore BrokenPipeErrorVictor Stinner2014-07-171-1/+5
| | | | | | | | If you want to handle the BrokenPipeError, you can easily reimplement communicate(). Add also a unit test to ensure that stdin.write() + stdin.drain() raises BrokenPipeError.
* Issue #21163: Fix "destroy pending task" warning in test_wait_errors()Victor Stinner2014-07-161-2/+2
|
* Issue #21163, asyncio: Ignore "destroy pending task" warnings for private tasksVictor Stinner2014-07-161-11/+23
| | | | in gather().
* asyncio tests: make quiet the logs of SSL handshake failures when running testsVictor Stinner2014-07-141-0/+16
| | | | in debug mode
* asyncio: sync with TulipVictor Stinner2014-07-145-41/+181
| | | | | | | | | | | | | | | | | | | | * Tulip issue #184: Log subprocess events in debug mode - Log stdin, stdout and stderr transports and protocols - Log process identifier (pid) - Log connection of pipes - Log process exit - Log Process.communicate() tasks: feed stdin, read stdout and stderr - Add __repr__() method to many classes related to subprocesses * Add BaseSubprocessTransport._pid attribute. Store the pid so it is still accessible after the process exited. It's more convinient for debug. * create_connection(): add the socket in the "connected to" debug log * Clean up some docstrings and comments. Remove unused unimplemented _read_from_self().
* asyncio: sync with TulipVictor Stinner2014-07-125-20/+209
| | | | | | | | | | | | | | | | | | | * 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: improve the documentation of serversVictor Stinner2014-07-111-1/+3
| | | | | | - Fix the documentation of Server.close(): it closes sockets - Replace AbstractServer with Server - Document Server.sockets attribute
* asyncio, Tulip issue 180: Make Server attributes and methods privateVictor Stinner2014-07-113-24/+25
| | | | | | | - loop, waiters and active_count attributes are now private - attach(), detach() and wakeup() methods are now private The sockets attribute remains public.
* asyncio: sync with TulipVictor Stinner2014-07-113-9/+14
| | | | | | | | | | * Tulip issue #182: Improve logs of BaseEventLoop._run_once() - Don't log non-blocking poll - Only log polling with a timeout if it gets events or if it timed out after more than 1 second. * Fix some pyflakes warnings: remove unused imports
* asyncio: sync with TulipVictor Stinner2014-07-102-10/+3
| | | | | | | - CoroWrapper.__del__() now reuses repr(CoroWrapper) to log the "... was never yielded from" warning - Improve CoroWrapper: copy also the qualified name on Python 3.4, not only on Python 3.5+
* asyncio: sync with TulipVictor Stinner2014-07-103-8/+28
| | | | | | | - repr(Task) and repr(CoroWrapper) now also includes where these objects were created. If the coroutine is not a generator (don't use "yield from"), use the location of the function, not the location of the coro() wrapper. - Fix create_task(): truncate the traceback to hide the call to create_task().
* asyncio: sync with TulipVictor Stinner2014-07-101-4/+14
| | | | | | | | - Issues #21936, #21163: Fix sporadic failures of test_future_exception_never_retrieved() - Handle.cancel() now clears references to callback and args - In debug mode, repr(Handle) now contains the location where the Handle was created.
* asyncion, Tulip issue 181: BaseEventLoop.create_datagram_endpoint() now waitsVictor Stinner2014-07-084-5/+18
| | | | | until protocol.connection_made() has been called. Document also why transport constructors use a waiter.
* asyncio: sync with TulipVictor Stinner2014-07-085-3/+20
| | | | | | | | | | | - Tulip issue 185: Add a create_task() method to event loops. The create_task() method can be overriden in custom event loop to implement their own task class. For example, greenio and Pulsar projects use their own task class. The create_task() method is now preferred over creating directly task using the Task class. - tests: fix a warning - fix typo in the name of a test function - Update AbstractEventLoop: add new event loop methods; update also the unit test
* asyncio: sync with TulipVictor Stinner2014-07-072-2/+2
| | | | | Backout the "Tulip issue 181: Faster create_connection()" changeset, it was a mistake.
* asyncio: sync with TulipVictor Stinner2014-07-073-4/+4
| | | | | | | | - 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-057-7/+21
| | | | | of a Future with call_soon(). Add an helper, a private method, to set the result only if the future was not cancelled.
* asyncio: sync with TulipVictor Stinner2014-07-023-7/+12
| | | | | | | | | | * _UnixSubprocessTransport: fix file mode of stdin. Open stdin in write mode, not in read mode * Examples: close the event loop at exit * More reliable CoroWrapper.__del__. If the constructor is interrupted by KeyboardInterrupt or the coroutine objet is destroyed lately, some the _source_traceback attribute doesn't exist anymore. * repr(Task): include also the future the task is waiting for
* Issue #21163: BaseEventLoop.run_until_complete() and test_utils.run_briefly()Victor Stinner2014-06-303-1/+14
| | | | | don't log the "destroy pending task" message anymore. The log is redundant for run_until_complete() and useless in run_briefly().
* asyncio: sync with TulipVictor Stinner2014-06-302-10/+51
| | | | | | | | | | | - Sort imports - Simplify/optimize iscoroutine(). Inline inspect.isgenerator(obj): replace it with isinstance(obj, types.GeneratorType) - CoroWrapper: check at runtime if Python has the yield-from bug #21209. If Python has the bug, check if CoroWrapper.send() was called by yield-from to decide if parameters must be unpacked or not. - Fix "Task was destroyed but it is pending!" warning in test_task_source_traceback()
* asyncio: sync with Tulip, add a new asyncio.coroutines moduleVictor Stinner2014-06-2811-182/+204
|
* asyncio, Tulip issue 137: In debug mode, save traceback where Future, Task andVictor Stinner2014-06-274-20/+67
| | | | | | | | | | | Handle objects are created. Pass the traceback to call_exception_handler() in the 'source_traceback' key. The traceback is truncated to hide internal calls in asyncio, show only the traceback from user code. Add tests for the new source_traceback, and a test for the 'Future/Task exception was never retrieved' log.
* asyncio, Tulip issue 137: In debug mode, add the traceback where the coroutineVictor Stinner2014-06-271-7/+10
| | | | object was created to the "coroutine ... was never yield from" log
* asyncio: Handle error handler: enhance formatting of the callbackVictor Stinner2014-06-251-2/+2
|
* asyncio, Tulip issue 177: Rewite repr() of Future, Task, Handle and TimerHandleVictor Stinner2014-06-253-53/+102
| | | | | | - Uniformize repr() output to format "<Class ...>" - On Python 3.5+, repr(Task) uses the qualified name instead of the short name of the coroutine
* asyncio: repr(Task) now also contains the line number even if the coroutine isVictor Stinner2014-06-241-2/+4
| | | | | | | | done: use the first line number of the code object instead of the current line number of the generator frame. The name of the coroutine is not enough because many coroutines may have the same name. It's a common case in asyncio tests for example.
* asyncio: Log an error if a Task is destroyed while it is still pendingVictor Stinner2014-06-242-0/+16
|
* asyncio: Fix BaseEventLoop._assert_is_current_event_loop(): get_event_loop()Victor Stinner2014-06-231-2/+5
| | | | raises an exception if there is no current loop
* asyncio, Tulip issue 171: BaseEventLoop.close() now raises an exception if theVictor Stinner2014-06-224-3/+7
| | | | | event loop is running. You must first stop the event loop and then wait until it stopped, before closing it.
* asyncio, Tulip issue 172: only log selector timing in debug modeVictor Stinner2014-06-221-2/+1
|
* asyncio: Enable the debug mode of event loops when the PYTHONASYNCIODEBUGVictor Stinner2014-06-221-1/+2
| | | | environment variable is set