Commit Graph

218 Commits

Author SHA1 Message Date
Victor Stinner 975735f729 asyncio, Tulip issue 177: Rewite repr() of Future, Task, Handle and TimerHandle
- Uniformize repr() output to format "<Class ...>"
- On Python 3.5+, repr(Task) uses the qualified name instead of the short name
  of the coroutine
2014-06-25 21:41:58 +02:00
Victor Stinner df29c4a83d asyncio: repr(Task) now also contains the line number even if the coroutine is
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.
2014-06-24 22:57:14 +02:00
Victor Stinner a02f81ff17 asyncio: Log an error if a Task is destroyed while it is still pending 2014-06-24 22:37:53 +02:00
Victor Stinner f328c7dc69 asyncio, Tulip issue 171: BaseEventLoop.close() now raises an exception if the
event loop is running. You must first stop the event loop and then wait until
it stopped, before closing it.
2014-06-23 01:02:37 +02:00
Victor Stinner 1580fe3fce asyncio, Tulip issue 172: only log selector timing in debug mode 2014-06-23 00:31:08 +02:00
Victor Stinner c082ee692b asyncio: Add an unit test to check that setting the PYTHONASYNCIODEBUG env var
enables debug mode of the event loop.
2014-06-23 00:19:33 +02:00
Victor Stinner 7b7120e159 asyncio: Enable the debug mode of event loops when the PYTHONASYNCIODEBUG
environment variable is set
2014-06-23 00:12:14 +02:00
Victor Stinner 0e6f52a211 asyncio, Tulip issue 105: in debug mode, log callbacks taking more than 100 ms
to be executed.
2014-06-20 17:34:15 +02:00
Victor Stinner 64d750b36b asyncio: Fix pyflakes errors
- Add a missing import
- Remove an unused import
- Remove unused variables
2014-06-18 03:25:23 +02:00
Victor Stinner c73701de72 asyncio: Refactor tests: add a base TestCase class 2014-06-18 01:36:32 +02:00
Victor Stinner d6f02fc649 asyncio: Refactor test__run_once_logging() to not rely on the exact number of
calls to time.monotonic(). Use a "fast select" and a "slow select" instead.
2014-06-18 01:22:15 +02:00
Victor Stinner 8d3e02ef5a asyncio: Set __qualname__ attribute of CoroWrapper in @coroutine decorator on
Python 3.5

- Drop __slots__ optimization of CoroWrapper to be able to set the __qualname__
  attribute.
- Add tests on __name__, __qualname__ and __module__ of a coroutine function
  and coroutine object.
- Fix test_tasks when run in debug mode (PYTHONASYNCIODEBUG env var set) on
  Python 3.3 or 3.4
2014-06-18 01:14:59 +02:00
Victor Stinner 66dc6b0f53 Issue #21723: asyncio.Queue: support any type of number (ex: float) for the
maximum size. Patch written by Vajrasky Kok.
2014-06-17 23:36:21 +02:00
Victor Stinner 4802c6ee55 Sync asyncio with Tulip: Fix test_tasks for Python 3.5
On Python 3.5, generator now gets their name from the function, no more from
the code. So we get the expected "notmuch" name instead of the generic "coro"
name.
2014-06-16 17:11:05 +02:00
Victor Stinner 307bccc6ff asyncio: Tulip issue 173: Enhance repr(Handle) and repr(Task)
repr(Handle) is shorter for function: "foo" instead of "<function foo at
0x...>". It now also includes the source of the callback, filename and line
number where it was defined, if available.

repr(Task) now also includes the current position in the code, filename and
line number, if available. If the coroutine (generator) is done, the line
number is omitted and "done" is added.
2014-06-12 18:39:26 +02:00
Victor Stinner bb2fc5b2a5 Issue #21326: Add a new is_closed() method to asyncio.BaseEventLoop
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".
2014-06-10 10:23:10 +02:00
Victor Stinner 3f9535b7f8 Fix asyncio tests on Windows: wait for the subprocess exit
Before, regrtest failed to remove the temporary test directory because the
process was still running in this directory.
2014-06-04 00:42:04 +02:00
Victor Stinner 27d411255a Issue #21651: Fix ResourceWarning when running asyncio tests on Windows.
Patch written by Claudiu Popa.
2014-06-04 00:23:26 +02:00
Victor Stinner 8551e0f3e0 cleanup test_asyncio/test_base_events.py: cm variable was unused 2014-06-04 00:18:41 +02:00
Victor Stinner a9fa2664ab Issue #21119: asyncio: Make sure that socketpair() close sockets on error
Close the listening socket if sock.bind() raises an exception.
2014-06-04 00:12:28 +02:00
Victor Stinner 223a624158 Issue #21119: asyncio now closes sockets on errors
Fix ResourceWarning: create_connection(), create_datagram_endpoint() and
create_unix_server() methods of event loop now close the newly created socket
on error.
2014-06-04 00:11:52 +02:00
Andrew Svetlov 3207a03035 Fix for raising exception not derived from BaseException in _SelectorSslTransport.resume_reading 2014-05-27 21:24:43 +03:00
Victor Stinner 93668f4459 asyncio: test_base_events: use mock.Mock instead of unittest.mock.Mock to
simplify the synchronization with Trollius
2014-05-20 15:57:08 +02:00
Guido van Rossum 7664eb0297 Fix test-order-dependend asyncio test failure caused by rev 909ea8cc86bbab92dbb6231668f403b7360f30fa. 2014-05-13 09:19:39 -07:00
Guido van Rossum bf88ffba5e asyncio: Fix upstream issue 168: StreamReader.read(-1) from pipe may hang if data exceeds buffer limit. 2014-05-12 10:04:37 -07:00
Guido van Rossum 3d139d8ed6 asyncio: Fix the second half of issue #21447: race in _write_to_self(). 2014-05-06 14:42:40 -07:00
Guido van Rossum 94ba146d11 asyncio: Add __weakref__ slots to Handle and CoroWrapper. Upstream issue #166. 2014-04-27 10:44:22 -07:00
Guido van Rossum 0cbc76880f asyncio: Add gi_{frame,running,code} properties to CoroWrapper (upstream #163). 2014-04-15 12:06:34 -07:00
Benjamin Peterson fa873f66c6 remove superfluous and useless line 2014-04-16 16:16:37 -04:00
Yury Selivanov 09cc169a03 asyncio.tasks: Make sure CoroWrapper.send proxies one argument correctly
Issue #21209.
2014-04-15 12:01:16 -04:00
Yury Selivanov f15f7484bb asyncio.tasks: Fix CoroWrapper to workaround yield-from bug in CPython < 3.4.1
Closes issue #21209.
2014-04-14 22:21:52 -04:00
Victor Stinner 1fd03a4a22 Issue #21155: asyncio.EventLoop.create_unix_server() now raises a ValueError if
path and sock are specified at the same time.
2014-04-07 11:18:54 +02:00
Victor Stinner d2403a21e4 Issue #20668: Remove tests.txt of test_asyncio
It's useless, tests are now discovered automatically.
2014-03-31 17:40:06 +02:00
Yury Selivanov 00abf385ac asyncio.tests: Autodiscover asyncio tests. Patch by Vajrasky Kok. Closes #20668 2014-03-27 12:21:20 -04:00
Victor Stinner 93569c2b3d asyncio: Ensure call_soon(), call_later() and call_at() are invoked on current
loop in debug mode. Raise a RuntimeError if the event loop of the current
thread is different.  The check should help to debug thread-safetly issue.
Patch written by David Foster.
2014-03-21 10:00:52 +01:00
Victor Stinner e6a537976e asyncio, Tulip issue 157: Improve test_events.py, avoid run_briefly() which is
not reliable
2014-03-06 01:00:36 +01:00
Victor Stinner eeeebcd816 asyncio: Synchronize with Tulip
* Issue #159: Fix windows_utils.socketpair()

  - Use "127.0.0.1" (IPv4) or "::1" (IPv6) host instead of "localhost", because
    "localhost" may be a different IP address
  - Reject also invalid arguments: only AF_INET/AF_INET6 with SOCK_STREAM (and
    proto=0) are supported

* Reject add/remove reader/writer when event loop is closed.
* Fix ResourceWarning warnings
2014-03-06 00:52:53 +01:00
Victor Stinner 658103f84e asyncio: simplify test_events.py, don't use non local variables and don't call
assert methods in coroutines.

It also simplify merges from Tulip to Trollius (Python 2 does not support non
local variables).
2014-02-26 11:31:55 +01:00
Victor Stinner f5e37037cc asyncio: Fix pyflakes warnings: remove unused variables and imports 2014-02-26 11:07:42 +01:00
Victor Stinner 24ba203504 asyncio: Replace "unittest.mock" with "mock" in unit tests
Use "from unittest import mock". It should simplify my work to merge new tests
in Trollius, because Trollius uses "mock" backport for Python 2.
2014-02-26 10:25:02 +01:00
Victor Stinner a90e8edaea asyncio: _check_resolved_address() must also accept IPv6 without flow_info and
scope_id: (host, port).
2014-02-20 21:59:38 +01:00
Victor Stinner 0211ed3e89 asyncio: ops, and now fix also the unit test for IPv6 address:
test_sock_connect_address()
2014-02-20 17:01:11 +01:00
Victor Stinner 7ef60cd8c2 asyncio, Tulip issue #136: Add get/set_debug() methods to BaseEventLoopTests.
Add also a PYTHONASYNCIODEBUG environment variable to debug coroutines since
Python startup, to be able to debug coroutines defined directly in the asyncio
module.
2014-02-19 23:15:02 +01:00
Victor Stinner 4ac30f1792 Issue #20682: Oops, fix test_create_connection() of test_asyncio (fix my previous commit) 2014-02-19 18:32:03 +01:00
Victor Stinner 8c33ffd9b6 Close #20682: Fix UNIX sockets tests of test_asyncio on Mac OS X Tiger
On Mac OS X Tiger (and older), getsockname() returns a zero-length address for
UNIX socket, and so 'sockname' extra info is None.
2014-02-19 18:10:32 +01:00
Yury Selivanov 2d01c0a080 asyncio: WriteTransport.set_write_buffer_size to call _maybe_pause_protocol 2014-02-19 11:10:52 -05:00
Yury Selivanov b41a42e316 asyncio: pep8-ify the code. 2014-02-18 22:56:15 -05:00
Yury Selivanov b0b0e628ee asyncio: Fix spelling and typos.
Thanks to Vajrasky Kok for discovering some of them.
2014-02-18 22:27:48 -05:00
Victor Stinner 8abac348a9 Issue #20682: test_asyncio, _basetest_create_connection() checks also the
sockname, as _basetest_create_ssl_connection().
2014-02-19 02:21:08 +01:00
Victor Stinner 884e40b982 asyncio, Tulip issue 143: UNIX domain methods, fix ResourceWarning and
DeprecationWarning warnings. create_unix_server() closes the socket on any
error, not only on OSError.
2014-02-19 01:45:59 +01:00
Victor Stinner 065ca25aae asyncio, Tulip issue 139: Improve error messages on "fatal errors"
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").
2014-02-19 01:40:41 +01:00
Yury Selivanov ff827f08ac asyncio: New error handling API. Issue #20681. 2014-02-18 18:02:19 -05:00
Yury Selivanov 88a5bf0b2e asyncio: Add support for UNIX Domain Sockets. 2014-02-18 12:15:06 -05:00
Victor Stinner 9141bff144 Issue #20667: KqueueEventLoopTests.test_read_pty_output() hangs also on OpenBSD 5.5. 2014-02-18 09:13:47 +01:00
Victor Stinner 5afffeab73 Issue #20667: test_asyncio: Skip KqueueEventLoopTests.test_read_pty_output() on
OpenBSD older than 5.5
2014-02-18 01:30:03 +01:00
Victor Stinner 740eedb826 Issue #20655: Fix test_asyncio, run also subprocess tests. Patch written by
Vajrasky Kok.
2014-02-18 00:11:21 +01:00
Victor Stinner 1ff0ee0be2 Fix test_asyncio/test_events.py: skip IPv6 if IPv6 is disabled on the host 2014-02-13 10:46:05 +01:00
Victor Stinner 28773465e6 ayncio, Tulip issue 129: BaseEventLoop.sock_connect() now raises an error if
the address is not resolved (hostname instead of an IP address) for AF_INET and
AF_INET6 address families.
2014-02-13 09:24:37 +01:00
Guido van Rossum b58f053e48 asyncio: Change as_completed() to use a Queue, to avoid O(N**2) behavior. Fixes issue #20566. 2014-02-12 17:58:19 -08:00
Victor Stinner 13b493e8a7 Issue #20495: Skip test_read_pty_output() of test_asyncio on FreeBSD older than
FreeBSD 8
2014-02-11 18:40:56 +01:00
Victor Stinner eb74876e99 asyncio, Tulip issue 131: as_completed() and wait() now raises a TypeError if
the list of futures is not a list but a Future, Task or coroutine object
2014-02-11 11:54:08 +01:00
Victor Stinner 4e8d2f25e2 asyncio, Tulip issue 130: Add more checks on subprocess_exec/subprocess_shell
parameters
2014-02-11 11:44:56 +01:00
Victor Stinner a125497ea3 asyncio, Tulip issue 126: call_soon(), call_soon_threadsafe(), call_later(),
call_at() and run_in_executor() now raise a TypeError if the callback is a
coroutine function.
2014-02-11 11:34:30 +01:00
Victor Stinner 6cf5c96630 Issue #20505: BaseEventLoop uses again the resolution of the clock to decide if
scheduled tasks should be executed or not.
2014-02-10 23:42:32 +01:00
Victor Stinner cf736f4e98 Issue #20505: Use even shorter sleep in test_timeout_rounding() to make the
test more reliable (= fail more often on Windows with HPET enabled).
2014-02-10 19:17:46 +01:00
Victor Stinner 1c143b19c8 Issue #20505: Add debug info to analyze sporaric failures of
test_timeout_rounding() on Windows XP buildbots.
2014-02-10 11:47:50 +01:00
Victor Stinner dc62b7e261 asyncio: Tulip issue 112: Inline make_handle() into Handle constructor 2014-02-10 00:45:44 +01:00
Victor Stinner 0c3949c963 asyncio: Remove Process.subprocess attribute; it's too easy to get inconsistent
Process and Popen objects
2014-02-09 02:51:40 +01:00
Guido van Rossum 313f829ce8 asyncio: Test fix. 2014-02-08 17:35:09 -08:00
Victor Stinner 87bf2772be asyncio tests: Remove scories of resolution/granularity 2014-02-09 01:25:52 +01:00
Victor Stinner 85310a50a9 Issue #20505: Remove resolution and _granularity from selectors and asyncio
* Remove selectors.BaseSelector.resolution attribute
* Remove asyncio.BaseEventLoop._granularity attribute
2014-02-07 23:34:58 +01:00
Yury Selivanov 622be340fd asyncio.tasks: Fix as_completed, gather & wait to work with duplicate coroutines 2014-02-06 22:06:16 -05:00
Yury Selivanov f0020f5d77 asyncio.streams.StreamReader: Add 'at_eof()' method 2014-02-06 00:14:30 -05:00
Yury Selivanov e694c9745f asyncio.streams: Use bytebuffer in StreamReader; Add assertion in feed_data 2014-02-05 18:11:13 -05:00
Guido van Rossum 3b55f0c622 asyncio: Cosmetic improvement to test__run_once_logging() mock argument. 2014-02-04 14:27:14 -08:00
Victor Stinner 1703bbbf89 Oops, undo unwanted changes in test_asyncio: mistakes of my the last sync with
Tulip (changeset d7ac90c0463a)
2014-02-03 23:59:52 +01:00
Victor Stinner b79eb0502c asyncio.subprocess: Replace Process.get_subprocess() method with a
Process.subprocess read-only property
2014-02-03 23:08:14 +01:00
Victor Stinner 9dd39f524d Issue #20472: test_asyncio: skip PTY tests on Mac OS X older than 10.6 2014-02-03 00:32:13 +01:00
Victor Stinner 915bcb0111 Issue #20400: Merge Tulip into Python: add the new asyncio.subprocess module
* 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)
2014-02-01 22:49:59 +01:00
Victor Stinner a0aa88ce89 test_asyncio: relax timing, the "AMD64 Windows Server 2008 [SB] 3.x" buildbot
looks to be slow
2014-02-01 04:11:16 +01:00
Victor Stinner 55effc6dd0 Issue #20452: Fix test_time_and_call_at() of test_asyncio on Windows
Use the granularity to check the minimum time delta, instead of arbitrary
value.
2014-02-01 02:18:52 +01:00
Victor Stinner 1144214639 Issue #20452: test_asyncio checks also the granularity 2014-02-01 02:17:54 +01:00
Victor Stinner 62510dced9 Issue #20452: test_asyncio: Add more info if the test fails 2014-01-31 16:39:10 +01:00
Victor Stinner 1506df2655 Issue #20455: Add a resolution attribute to IocpProactor (1 ms) 2014-01-31 16:26:38 +01:00
Victor Stinner 49d0f4e428 Issue #20452: Remove debug code, no more needed 2014-01-31 12:59:43 +01:00
Victor Stinner dcd9740ad2 Issue #20452: select and selectors round (again) timeout away from zero for
poll and epoll

Improve also debug info to analyze the issue
2014-01-31 12:12:53 +01:00
Victor Stinner 31f65044a9 Issue #20452: Oops, fix debug code :-/
Add also event more debug info
2014-01-31 10:55:55 +01:00
Victor Stinner 0278032110 Issue #20452: add more info in case of test_asyncio failure to try to debug the
failure on buildbot "x86 Ubuntu Shared 3.x"
2014-01-31 09:29:35 +01:00
Guido van Rossum a849be9c64 asyncio: Fix misc whitespace issues. 2014-01-30 16:05:28 -08:00
Victor Stinner 9572898282 asyncio: Future.set_exception(exc) should instantiate exc if it is a class. 2014-01-30 16:01:54 -08:00
Victor Stinner e623a12297 asyncio: subprocess_shell() and subprocess_exec() now raise ValueError instead of assert.
Moreover, bufsize different than 0 is now considered as an error.
2014-01-29 14:35:15 -08:00
Guido van Rossum 48c66c3dd8 asyncio: wait_for() now accepts None as timeout (Victor Stinner). 2014-01-29 14:30:38 -08:00
Guido van Rossum fef7098ef9 asyncio: Rename {Empty,Full} to {QueueEmpty,QueueFull} and no longer get them from queue.py. 2014-01-25 17:24:51 -08:00
Guido van Rossum ab3c88983b asyncio: Locks refactor: use a separate context manager; remove Semaphore._locked. 2014-01-25 16:51:57 -08:00
Victor Stinner 669eeaf933 Merge latest Tulip into asyncio
- Make the new granularity attribute private
- Simplify BaseEventLoop._run_once(): avoid math.ceil(), use simple arithmetic
  instead
2014-01-26 00:02:31 +01:00
Victor Stinner 128ee220e2 asyncio: Don't export BaseEventLoop, BaseSelectorEventLoop nor
BaseProactorEventLoop

Import them from submodules if you really need them.
2014-01-25 22:22:18 +01:00
Victor Stinner 8dffc456d7 Update asyncio from the Tulip project
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
2014-01-25 15:32:06 +01:00
Victor Stinner f67255ab94 Issue #20311: asyncio: Add a granularity attribute to BaseEventLoop: maximum
between the resolution of the BaseEventLoop.time() method and the resolution of
the selector. The granuarility is used in the scheduler to round time and
deadline.
2014-01-25 15:01:33 +01:00
Victor Stinner 421e49b5c1 asyncio: wait_for() now cancels the future on timeout. Patch written by Gustavo
Carneiro.
2014-01-23 17:40:59 +01:00
Victor Stinner 8ce6e1100e Close #20365: Skip test_asyncio.test_events.test_read_pty_output() on Mac OS X
older than 10.9 (Maverick). kqueue doesn't support character devices (PTY) on
Mac OS X older than 10.9.
2014-01-23 17:26:06 +01:00