Ultra fast asyncio event loop.

Overview
https://travis-ci.org/MagicStack/uvloop.svg?branch=master PyPI - Downloads

uvloop is a fast, drop-in replacement of the built-in asyncio event loop. uvloop is implemented in Cython and uses libuv under the hood.

The project documentation can be found here. Please also check out the wiki.

Performance

uvloop makes asyncio 2-4x faster.

https://raw.githubusercontent.com/MagicStack/uvloop/master/performance.png

The above chart shows the performance of an echo server with different message sizes. The sockets benchmark uses loop.sock_recv() and loop.sock_sendall() methods; the streams benchmark uses asyncio high-level streams, created by the asyncio.start_server() function; and the protocol benchmark uses loop.create_server() with a simple echo protocol. Read more about uvloop in a blog post about it.

Installation

uvloop requires Python 3.7 or greater and is available on PyPI. Use pip to install it:

$ pip install uvloop

Note that it is highly recommended to upgrade pip before installing uvloop with:

$ pip install -U pip

Using uvloop

Call uvloop.install() before calling asyncio.run() or manually creating an asyncio event loop:

import asyncio
import uvloop

async def main():
    # Main entry-point.
    ...

uvloop.install()
asyncio.run(main())

Building From Source

To build uvloop, you'll need Python 3.7 or greater:

  1. Clone the repository:

    $ git clone --recursive [email protected]:MagicStack/uvloop.git
    $ cd uvloop
    
  2. Create a virtual environment and activate it:

    $ python3.7 -m venv uvloop-dev
    $ source uvloop-dev/bin/activate
    
  3. Install development dependencies:

    $ pip install -e .[dev]
    
  4. Build and run tests:

    $ make
    $ make test
    

License

uvloop is dual-licensed under MIT and Apache 2.0 licenses.

Comments
  • UVTimer leaks

    UVTimer leaks

    • uvloop version: 0.4.29
    • python version: 3.5.1
    • platform: FreeBSD

    We are seeing a serious memory leak that only shows up when using UVLoop on Gunicorn. Examining the GC state does not show anything useful, which indicates to me that it is likely inside native code, so I report this here. Under moderate load, we see each Gunicorn worker taking 2GB ram within 18-24 hours.

    We are presently retesting under 0.4.32 and will update if we still see it. If you have any suggestions for debugging it that may be helpful, that would be useful too. We only see this leak under UVLoop and not the default asyncio loop, so it has to be related to UVLoop.

    resolved 
    opened by kaniini 32
  • Rewrite asyncio/sslproto.py

    Rewrite asyncio/sslproto.py

    Problems with sslproto.py

    • The code is very complex and hard to reason about. At this point it's pretty much unmaintainable, many bugs on bugs.python.org linger unresolved just because we don't have capacity to debug them or review PRs.

    • It's very slow. SSL connections are 3-4x slower than regular connections.

    • It has many yet unresolved problems associated with SSL connection shutdown and cleanup:

      • https://bugs.python.org/issue30698
      • https://bugs.python.org/issue29406
      • https://bugs.python.org/issue25292
    • We don't have enough functional tests for SSL in asyncio. Especially ones that test cancellation & timeouts thoroughly enough.

    Requirements for the new implementation

    • Easy to understand code. Ideally, the state machine should be implemented right in the SSLProtocol (so no SSLPipe abstraction). A good example of a protocol state machine is asyncpg's CoreProtocol <-> Protocol <-> Connection mechanism.

    • Performance. Ideally, SSL connections shouldn't be more than 10% slower.

    • Tests. Nathaniel once mentioned that Trio's SSL tests are very robust and that he found bugs in CPython's ssl module with them. We maybe want to backport them to asyncio.

    • SSL tunneled through SSL should be naturally supported.

    Suggested steps towards the new implementation

    1. Try to benchmark the current asyncio/sslproto.py. Maybe we'll be able to pinpoint the exact bottleneck that makes it so slow; what if there's a bug in ssl module? Most likely there's no single bottleneck, and the reason for poor performance is just its inefficient code.

    2. Implement a new SSL state machine/protocol in pure Python (I suggest to use new asyncio.BufferedProtocol from the beginning, though.) Get it to the point that it passes asyncio's existing SSL tests. Add more tests.

    3. Once we have a working pure Python implementation, we can (a) contribute it to Python 3.8, (b) start optimizing it in Cython for uvloop.

    cc @fantix

    enhancement 
    opened by 1st1 30
  • Hang waiting for create_server

    Hang waiting for create_server

    • uvloop 0.4.33:
    • python 3.5.1, 3.5.2:
    • platform Mac OS X, Ubuntu 16.04/4.4.12-boot2docker:

    I need some suggestions for debugging server startup hangs.

    Startup code looks like:

     cr = loop.create_server(self.factory, addr[0], addr[1],
                                    reuse_address=True, ssl=ssl)
    f = asyncio.async(cr, loop=loop)
    server = loop.run_until_complete(f)
    

    What's sometimes happening, in the context of the ZEO tests, is that the run_loop_until_complete call above never returns.

    This is in a port of ZEO, github.com/zopefoundation/ZEO, to asyncio. The ZEO tests are exhaustive, and I suspect in uvloop's case, exhausting. :) The tests start and stop servers 10s, maybe 100s of times in a test runs that typically lasts a few minutes. If I run a smaller subset of the tests I don't get a hang.

    Most tests run the server as a subprocess using multiprocessing. Some tests run the server using threading. It appears that the server isn't exiting, but merely hanging.

    Do you have any suggestions for how to debug this? I've tried setting PYTHONASYNCIODEBUG=1 and enabling debug logging, but that isn't yielding any additional information..

    libuv 
    opened by jimfulton 26
  • Rewrite sslproto.py

    Rewrite sslproto.py

    State transition:

    State transition

    Recv/send calling chain:

    Recv/send calling chain

    Reworked flow control:

    Reworked flow control

    SSLProtocol internals (shutdown detail):

    SSLProtocol

    SSLObject methods internals:

    SSLObject

    Refs #158, ~this is a WIP yet, please kindly wait until ready for review.~

    TODOs:

    • [x] Pass cpython tests
    • [x] Pass uvloop tests
    • [x] Test SSL over SSL
    • [x] Correct shutdown (graceful close) data flush and cover with test
    • [x] Test renegotiation (with pyOpenSSL)
    • [x] Port Trio tests
    • [x] Maybe extract a cdef class for both performance and readibility
    • [x] Add test for https://bugs.python.org/issue30698
    • [x] https://bugs.python.org/issue29406
    • [x] https://bugs.python.org/issue25292
    • [x] Fix eof_received() implementation
    • [x] Backport to cpython and pass tests
    • [x] Cythonize transport
    • [x] Extract high/low water mark
    • [x] Make sure memory management is good
    • [x] ~Check sendfile support~
    opened by fantix 24
  • Unable to install uvloop

    Unable to install uvloop

    pip install uvloop throws this error

        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "/tmp/pip-build-3p6l9uj5/uvloop/setup.py", line 81, in <module>
            include_package_data=True
          File "/usr/lib/python3.5/distutils/core.py", line 148, in setup
            dist.run_commands()
          File "/usr/lib/python3.5/distutils/dist.py", line 955, in run_commands
            self.run_command(cmd)
          File "/usr/lib/python3.5/distutils/dist.py", line 974, in run_command
            cmd_obj.run()
          File "/home/anand/.virtualenvs/35/lib/python3.5/site-packages/setuptools/command/install.py", line 61, in run
            return orig.install.run(self)
          File "/usr/lib/python3.5/distutils/command/install.py", line 583, in run
            self.run_command('build')
          File "/usr/lib/python3.5/distutils/cmd.py", line 313, in run_command
            self.distribution.run_command(command)
          File "/usr/lib/python3.5/distutils/dist.py", line 974, in run_command
            cmd_obj.run()
          File "/usr/lib/python3.5/distutils/command/build.py", line 135, in run
            self.run_command(cmd_name)
          File "/usr/lib/python3.5/distutils/cmd.py", line 313, in run_command
            self.distribution.run_command(command)
          File "/usr/lib/python3.5/distutils/dist.py", line 974, in run_command
            cmd_obj.run()
          File "/home/anand/.virtualenvs/35/lib/python3.5/site-packages/setuptools/command/build_ext.py", line 49, in run
            _build_ext.run(self)
          File "/usr/lib/python3.5/distutils/command/build_ext.py", line 338, in run
            self.build_extensions()
          File "/tmp/pip-build-3p6l9uj5/uvloop/setup.py", line 40, in build_extensions
            self.build_libuv()
          File "/tmp/pip-build-3p6l9uj5/uvloop/setup.py", line 35, in build_libuv
            subprocess.run(['make', j_flag], cwd=LIBUV_DIR, env=env, check=True)
          File "/usr/lib/python3.5/subprocess.py", line 711, in run
            output=stdout, stderr=stderr)
        subprocess.CalledProcessError: Command '['make', '-j4']' returned non-zero exit status 2
    
        ----------------------------------------
    
    resolved 
    opened by ChillarAnand 21
  • 'coroutine' object is not iterable

    'coroutine' object is not iterable

    • uvloop version: 0.9.1
    • Python version: 3.6
    • Platform: Ubuntu Xenial

    Version 0.9.1: I got an error

     File "/app/app/<***>/utils.py", line 35, in <***>
        async with app['client_session'].get(url) as response:
      File "/usr/local/lib/python3.6/dist-packages/aiohttp/client.py", line 690, in __aenter__
        self._resp = yield from self._coro
      File "/usr/local/lib/python3.6/dist-packages/aiohttp/client.py", line 267, in _request
        conn = yield from self._connector.connect(req)
      File "/usr/local/lib/python3.6/dist-packages/aiohttp/connector.py", line 402, in connect
        proto = yield from self._create_connection(req)
      File "/usr/local/lib/python3.6/dist-packages/aiohttp/connector.py", line 748, in _create_connection
        _, proto = yield from self._create_direct_connection(req)
      File "/usr/local/lib/python3.6/dist-packages/aiohttp/connector.py", line 831, in _create_direct_connection
        req=req, client_error=client_error)
      File "/usr/local/lib/python3.6/dist-packages/aiohttp/connector.py", line 796, in _wrap_create_connection
        return (yield from self._loop.create_connection(*args, **kwargs))
    TypeError: 'coroutine' object is not iterable
    

    Version 0.8.1: Not reproduced

    The error does not depend on other libraries.

    opened by oleksandr-kuzmenko 20
  • uvloop install fail in docker w/ pip install

    uvloop install fail in docker w/ pip install

    Hello! Trying to install uvloop in a python app within a docker image. I am currently getting the following errors (below).

    • uvloop version: latest
    • Python version: 3.7
    • Platform: Docker (python:alpine3.7)
    • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: haven't tried

    unable to install uvloop in docker, the same configuration works outside of the container. requirements.txt: asyncio uvloop asyncpg Dockerfile: RUN python3 -m pip install -r requirements.txt

    Error:

    Collecting uvloop (from -r requirements.txt (line 3)) Downloading https://files.pythonhosted.org/packages/d4/50/385f5dfd008508750a255ae742aaea6cc7f58877d9444b2d759543b0ee72/uvloop-0.10.1.tar.gz (1.9MB) Collecting asyncpg==0.16.0 (from -r requirements.txt (line 4)) Downloading https://files.pythonhosted.org/packages/89/62/6d218bc7d1412b837ed6f006a42a660fc970c3135c22c55f2370a93e11d4/asyncpg-0.16.0.tar.gz (615kB) Complete output from command python setup.py egg_info: error in asyncpg setup command: 'extras_require' requirements cannot include environment markers, in 'test': 'uvloop>=0.8.0; platform_system != "Windows"'

    again, the same requirements file work outside of docker (mac os + python 3.6)

    opened by pepie 19
  • uvloop alpha release

    uvloop alpha release

    Some ToDo items we need completed before we make an alpha release:

    • [x] Implement loop.create_connection
    • [x] Add few more tests for loop.create_server to increase the coverage
    • [x] Add a few high-level tests involving aiohttp or another real codebase
    • [x] Implement loop.create_unix_server
    • [x] Implement loop.create_unix_connection
    • [x] Implement loop.subprocess_shell and loop.subprocess_exec
    • [x] Implement loop.getnameinfo
    • [x] Implement loop.add_signal_handler and loop.remove_signal_handler
    • [x] Implement loop.connect_read_pipe and loop.connect_write_pipe
    • [x] Implement SSL
    • [x] Implement loop.create_datagram_endpoint
    opened by 1st1 19
  • Support for PY37 without contextvars

    Support for PY37 without contextvars

    This MR aligns the uvloop code to become compatible, not production ready, with PY37 adding the following changes:

    • Support for the new API used behind the set_debug function.
    • Adds the context=None KW to those functions that will receive it when uvloop runs with PY37.
    • Former asyncio.test_utils moved as an uvloop test resource.

    New MR on top of that to enable contextvars should be expected.

    opened by pfreixes 18
  • uvloop build failed on Python 3.8

    uvloop build failed on Python 3.8

    • uvloop version: 0.13.0
    • Python version: 3.8
    • Platform: Linux (Ubuntu Xenial, Fedora 30)
    • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: No, can't even build uvloop

    Hello,

    Two days ago new stable Python version 3.8.0 has been released. Today I updated test matrix for one of my projects and noticed uvloop fails to install: https://travis-ci.org/Snawoot/postfix-mta-sts-resolver/jobs/598694743

    Steps to reproduce:

    pip3.8 install uvloop
    
    fixed in master 
    opened by Snawoot 17
  • memory leak with 0.12.0

    memory leak with 0.12.0

    • uvloop version: 0.12.0
    • Python version: 3.7.2
    • Platform: Mac os and Docker
    • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: Have not tried yet

    Recently I upgraded from 0.11.3 to 0.12.0. I use uvloop to constantly pull data from an API and insert into a database. After running for a couple of minutes, I found that my memory usage jumped from ~100MB to ~450mb. Has anybody else run into this issue? I have a lot going on so reproducing it with a smaller gist would be hard right now. But reverting back to 0.11.3 immediately fixed the issue. So I am guessing something is related to the upgrade.

    bug 
    opened by amir20 17
  • Fix ci status badge error

    Fix ci status badge error

    Hello, this PR fixes the CI status badge error on the README file and documentation page (https://uvloop.readthedocs.io/).

    You can read the details here: https://github.com/badges/shields/issues/8671

    Before Screenshot 2023-01-03 at 1 23 43 Screenshot 2023-01-03 at 1 37 33

    After Screenshot 2023-01-03 at 1 27 55 Screenshot 2023-01-03 at 1 37 09

    opened by shuuji3 1
  • uvloop pypy3.9 error on import

    uvloop pypy3.9 error on import

    • uvloop version: 0.17.0
    • Python version: pypy3.9
    • Platform: Debian Bullseye
    • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: Yes
    • Does uvloop behave differently from vanilla asyncio? How?: Vanilla asyncio does not create this error

    uvloop fails to import with the following traceback

      File "/var/gpob/GB.py", line 36, in <module>
        import uvloop
      File "/usr/lib/pypy3.9/site-packages/uvloop/__init__.py", line 7, in <module>
        from .loop import Loop as __BaseLoop  # NOQA
    ImportError: /usr/lib/pypy3.9/site-packages/uvloop/loop.pypy39-pp73-x86_64-linux-gnu.so: undefined symbol: PyContext_CopyCurrent```
    opened by owenwastaken 0
  • uvloop pypy3.9 installing problem

    uvloop pypy3.9 installing problem

    I've pypy3.9 and got this issue when try to install uvloop via pip In file included from uvloop/loop.c:767: uvloop/includes/compat.h:74:12: error: implicit declaration of function 'PyContext_CopyCurrent' is invalid in C99 [-Werror,-Wimplicit-function-declaration] return PyContext_CopyCurrent(); I opened compat.h and it seems to have problems with including "Python.h".

    opened by federikowsky 0
  • loop.stop() different behavior with loop.run_forever() in asyncio vs. uvloop

    loop.stop() different behavior with loop.run_forever() in asyncio vs. uvloop

    • uvloop version: 0.17.0
    • Python version: 3.8.6
    • Platform: Linux
    • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: yes
    • Does uvloop behave differently from vanilla asyncio? How?: yes

    Hi @1st1,

    First of all thank you for your work on uvloop, it's been really useful.

    I maintain an application that makes heavy usage of asyncio. Whilst migrating to uvloop, I noticed a weird behavior with loop.stop and loop.run_forever methods in uvloop.

    From the asyncio docs: If stop() is called while run_forever() is running, the loop will run the current batch of callbacks and then exit. Note that new callbacks scheduled by callbacks will not run in this case; instead, they will run the next time run_forever() or run_until_complete() is called.

    I believe that the highlighted sentence is false and doesn't apply to uvloop (which makes its behavior differ from asyncio): Note that new callbacks scheduled by callbacks will not run in this case.

    Consider the (really convoluted, sorry about that - didn't find an easier/better way to reproduce even though I'm pretty sure there is) following code:

    import asyncio
    
    
    async def dummy(aw):
        try:
            while True:
                print('Sending')
                future = aw.send(None)
                if not future:
                    print('Yield')
                    await asyncio.sleep(0)
                else:
                    print('Whatever')
        except StopIteration as e:
            return e.value
    
    
    class Waiter:
        def __init__(self) -> None:
            self.started = False
            self.done = False
    
        async def wait_on(self, aw):
            self.started = True
            print('Starting')
            await dummy(aw)
            print('Done')
            self.done = True
    
    
    async def suspend():
        print('Suspending')
        await asyncio.sleep(0)
        print('Suspended')
        return True
    
    
    waiter = Waiter()
    loop = asyncio.get_event_loop()
    loop.create_task(waiter.wait_on(suspend()))
    loop.call_soon(loop.stop)
    print('Running forever')
    loop.run_forever()
    assert not waiter.done
    print('Exit')
    

    I added some print statements to better see what happens - we're pretty much doing some dark magic but the important part is what we're trying to achieve: We want to run one iteration of the event loop (until the cb loop.stop is called - which will make loop.run_forever return). Therefore the stdout for above asyncio code is as follow:

    Running forever
    Starting
    Sending
    Suspending
    Yield
    Exit
    

    Notice that no AssertionError is raised. The asyncio.sleep(0) in dummy gives a chance to run the cb loop.stop whichs makes run_forever method return and we gracefully exit. The "callbacks scheduled by callbacks" do not run, as mentioned in the asyncio docs.

    Now let's make usage of uvloop, by simply adding it at the beginning of our run statements:

    uvloop.install()   # <--- JUST ADDED THIS
    waiter = Waiter()
    loop = asyncio.get_event_loop()
    loop.create_task(waiter.wait_on(suspend()))
    loop.call_soon(loop.stop)
    print('Running forever')
    loop.run_forever()
    assert not waiter.done
    print('Exit')
    

    Here is the stdout:

    Running forever
    Starting
    Sending
    Suspending
    Yield
    Sending
    Suspended
    Done
    Traceback (most recent call last):
      File "./xxxxx.py", line 47, in <module>
        assert not waiter.done
    AssertionError
    

    We now have a completely different behavior. After some debugging, the loop.stop is still indeed being called when the Yield statement is printed but instead of making the loop.run_forever return immediately, it seems that uvloop gives a chance to other callbacks to run before - which is ultimately why we see that stdout and the AssertionError is being raised. That makes the asyncio statement false: Note that new callbacks scheduled by callbacks will not run in this case;

    I'm not saying this is a bug - this might be one of the area where you made a well-thought decision for uvloop; The docstring for the stop method in uvloop seems to indicate it. Maybe it is documented somewhere?

    The question: Am I missing something/doing something wrong (besides all the dark magic indeed)? Is there a way to really pause execution of callbacks when using run_forever (and resume it later) with uvloop just like we can with the asyncio method described by @asvetlov in this stackoverflow post?

    For the sake of completeness (even though I'm not sure this will help), I added a loop.print_debug_info() right before the assert when using uvloop - here is the output:

    ---- Process info: -----
    Process memory:            13964
    Number of signals:         0
    
    --- Loop debug info: ---
    Loop time:                 9854077.307
    Errors logged:             0
    
    Callback handles:          2        | 7
    Timer handles:             0        | 0
    
                            alive  | closed  |
    UVHandles               python | libuv   | total
                            objs   | handles |
    -------------------------------+---------+---------
        UVAsync                  1 |       0 |       1
        UVCheck                  1 |       0 |       1
        UVIdle                   1 |       0 |       1
        UVPoll                   1 |       0 |       1
    
    uv_handle_t (current: 4; freed: 0; total: 4)
    
    --- Streams debug info: ---
    Write errors:              0
    Write without poll:        0
    Write contexts:            0        | 0
    Write failed callbacks:    0
    
    Read errors:               0
    Read callbacks:            0
    Read failed callbacks:     0
    Read EOFs:                 0
    Read EOF failed callbacks: 0
    
    Listen errors:             0
    Shutdown errors            0
    
    --- Polls debug info: ---
    Read events:               0
    Read callbacks failed:     0
    Write events:              0
    Write callbacks failed:    0
    
    --- Sock ops successful on 1st try: ---
    Socket try-writes:         0
    
    opened by TheoBabilon 0
Releases(v0.17.0)
  • v0.17.0(Sep 14, 2022)

    This release adds Python 3.11 support, updates bundled libuv to 1.43.0 and fixes a handful of issues.

    Changes

    • Expose uv_loop_t pointer for integration with other C-extensions (#310) (by @pranavtbhat in b332eb85 for #310)

    • Support python 3.11+ (#473) (by @zeroday0619 in 8e42921d for #473)

    • Expose libuv uv_fs_event functionality (#474) (by @jensbjorgensen @fantix in 74d381e8 for #474)

    • Activate debug mode when -X dev is used (by @jack1142 in 637a77a3)

    • Expose uv_version() for libuv API compatibility (#491) (by @fantix in 089f6cbf for #491)

    • Fix loop.getaddrinfo() and tests (#495) (by @fantix in 598b16fd for #495)

    • Bump to libuv 1.43.0 (by @fantix in 94e5e535)

    Fixes

    • _TransProtPair is no longer defined in asyncio.events (by @jensbjorgensen in fae5f7fb)

    • use a TypeVar for asyncio.BaseProtocol (#478) (by @graingert in 3aacb352 for #478)

    • Fix segfault in TimerHandle.when() after cleared (by @jensbjorgensen in c39afff8 for #469)

    • Avoid self._errpipe_write double close (#466) (by @graingert in 72140d7e for #466)

    • Fix typo in test (#456) (by @kianmeng in 033d52d0 for #456)

    • Fix potential infinite loop (#446) (by @kfur in ada43c06 for #446)

    • use a stack of self._fds_to_close to prevent double closes (#481) (by @graingert in 3214cf68 for #481)

    • Fix incorrect main thread id value forking from a thread (#453) (by @horpto @fantix in e7934c88 for #453)

    • create_subprocess_exec should treat env={} as empty environment (#439) (#454) (by @byllyfish in e04637e0 for #439)

    • Queue write only after processing all buffers (#445) (by @jakirkham @fantix in 9c6ecb62 for #445)

    • Drop Python 3.6 support for thread ident (by @fantix in 9c37930e)

    • bugfix: write to another transport in resume_writing() fails (#498) (by @fantix in d2deffef for #498)

    Build

    • Upgrade GitHub Actions (#477) (#480) (by @cclauss in fcbf422d for #477, 10086942 for #480)

    • typo same as same (by @YoSTEALTH in fedba80a)

    • setup.py: allow to override extra_compile_args (#443) (by @giuliobenetti in a130375f for #443)

    • Drop hack in setup.py in finalize_options (492) (by @fantix in 2f1bc83c for #492)

    • Fix tests invocation on release CI worklow (#489) (by @ben9923 in d6a2b597 for #489)

    Documentation

    • use asyncio.Runner loop_factory on 3.11+ (#472) (by @graingert in 31ba48ca for #472)

    • Fix CI badge in docs, remove remaining Travis CI references from docs (by @Nothing4You in c6901a74)

    • Fix typo in README (by @monosans in 73d7253b)

    Source code(tar.gz)
    Source code(zip)
  • v0.16.0(Aug 10, 2021)

    This release adds Python 3.10 support, updates bundled libuv to 1.42.0 and fixes a handful of issues.

    Changes

    • Python 3.10 support (#432) (by @elprans in 2519e2df for #432)

    • Bump vendored libuv to 1.42.0 (#433) (by @elprans in a62f7818 for #433)

    • Use cibuildwheel to build wheels (#435) (by @elprans in 20febe0b for #435)

    • Add support for <timer handle>.when() (by Jens Jorgensen in 62b2af9c)

    Fixes

    • Fix ref issue when protocol is in Cython (by @fantix in 70cafc82 for #2222)

    • Set python_requires in setup.py (by @graingert in c808a663)

    • SSL: schedule first data after waiter wakeup (by @fantix in 2081db89)

    • Fix a possible race condition in sslproto test (by @fantix in b0526cd5 for #412)

    • Fix call_soon_threadsafe thread safety (by @fantix in 4b803b15)

    Source code(tar.gz)
    Source code(zip)
  • v0.15.3(Jul 13, 2021)

    Bug Fixes

    • SSL: schedule first data after waiter wakeup (by @fantix in 0df12282)

    • Fix a possible race condition in sslproto test (by @fantix in 2e71c4c2 for #412)

    • Fix call_soon_threadsafe thread safety (by @fantix and @hehaha in 6387a4e4 for #408)

    Source code(tar.gz)
    Source code(zip)
  • v0.15.2(Feb 19, 2021)

  • v0.15.1(Feb 15, 2021)

  • v0.15.0(Feb 10, 2021)

    New Features

    • Add name keyword argument to loop.create_task() (by @fantix in d51ce367 for #309)

    • Add typing support (by @bryanforbes in 9426e2b1, for #358)

    Bug Fixes

    • SSL: many improvements (by @fantix in 6476aad6, 8beacd26, 98e113ee, ae44ec2d, @asvetlov in 9bc4a204)

    • Fix KeyboardInterrupt handling logic (by @1st1 in c32c7039 for #295, @jack1142 in 8c471f82 for #337)

    • Python 3.8/3.9 compatibility fixes, drop support for 3.5/3.6 (by @jack1142 in 28702195 for #314, @achimnol in 0d14ec64 for #328, @aeros in 6ef69a79 for #349, @shadchin in 1fd90665, @fantix in 465717fd, 200e1404, afc3ee8f, cdd2218f, b7048b94)

    • UDP: multiple bug fixes (by @fantix in 1d9267af for #319, 9e017e6e for #304, 506a2aa1)

    • Pipe: a critical crash fix that affects subprocess, pipe and socketpair (by @fantix in 5d41af80 and @tardyp in c3929720 for #311 #312 #317)

    • Restore context on protocol callbacks (by @versusvoid in 7b202ccf for #305, @fantix in f691212b)

    • Subprocess: stdio bug fixes (by @fantix in 8cdb3002 for #136, @lovasoa in 68db1a23 for #363)

    • Sock: fix issue in sock_connect() for large concurrency (by @fantix in fe3d0281 for #378)

    • Misc fixes about docs URL, test typo, and CI compatibility (by @asfaltboy in 38105305, @felixonmars in fcb37350, @fantix in 6596685a)

    Build

    • Check Cython version semantically (by @YoSTEALTH in 5dc299b7)

    • Add .flake8 to distribution tarball (by @jlaine in e8eb5026 for #330)

    • Switch to Github actions (by @elprans in 3be8967e, e21ceea0, @fantix in 311997ed)

    • Bump libuv to v1.40.0 (by @fantix in 998c19ec)

    Source code(tar.gz)
    Source code(zip)
  • v0.14.0(Nov 5, 2019)

    New Features

    • Add support for Python 3.8. (by @1st1 in 5f48dab8, 51636f7b)

    Bug Fixes

    • Multiple fixes in the SSL/TLS layer. (by @fantix in 82104fb6 for #263, 7fcbfed1 for #255, e6fd6377)

    • Restore signal.wakeup_fd after the event loop is closed. (by @vladima in 48d376d3, @1st1 in d76d9827)

    • Handle large timeouts in loop.call_later(). (by @1st1 in 1a0d6578 for #259)

    • Fix possible feezing of uvloop on os.fork. (by @grungy-ado in fde5d14f)

    • Better handle Unix sockets for datagram transports. (by @mosquito and @1st1 in dd4cb7ac for #269)

    • Avoid double connecting to remote_addr for datagram transports. (by @1st1 in bed926c5 for #276)

    Build

    • Bump Cython to 0.29.13. (by @1st1 in 65c1a045)

    • Bump libuv to v1.33.1. (by @1st1 in 34fd827e)

    Source code(tar.gz)
    Source code(zip)
  • v0.14.0rc2(Oct 29, 2019)

  • v0.14.0rc1(Oct 25, 2019)

    New Features

    • Add support for Python 3.8. (by @1st1 in 5f48dab8, 51636f7b)

    Bug Fixes

    • Multiple fixes in the SSL/TLS layer. (by @fantix in 82104fb6 for #263, 7fcbfed1 for #255)

    • Restore signal.wakeup_fd after the event loop is closed. (by @vladima in 48d376d3)

    • Handle large timeouts in loop.call_later(). (by @1st1 in 1a0d6578 for #259)

    • Fix possible feezing of uvloop on os.fork. (by @grungy-ado in fde5d14f)

    • Better handle Unix sockets for datagram transports. (by @mosquito and @1st1 in dd4cb7ac for #269)

    • Avoid double connecting to remote_addr for datagram transports. (by @1st1 in bed926c5 for #276)

    Build

    • Bump Cython to 0.29.13. (by @1st1 in 65c1a045)

    • Bump libuv to v1.33.1. (by @1st1 in 34fd827e)

    Source code(tar.gz)
    Source code(zip)
  • v0.13.0(Aug 14, 2019)

    New Features

    • Implement Server.start_serving() and related APIs. (by @jlaine in 7a4f00a3)

    • Make Server an asynchronous context manager. (by @jlaine in d6c67e7a for #221)

    Performance

    • Start using high-performance uv_udp_t handle. This should result in a significantly faster UDP support. (by @1st1 in c2b65bc8)

    • Make address validation faster in udp.sendto(). (by @1st1 in 46c5e9eb)

    Misc

    • OSError is no longer logged by Transports. This matches asyncio behaviour in 3.8. (by @Tobotimus in ef29dab2)

    Build

    • Upgrade to libuv v1.31.0. (by @1st1 in c2b65bc8 and 1fad621f)

    • Use manylinux-2010. This means we no longer provide 32bit builds for Linux. (by @1st1 in 3174b7d3)

    Source code(tar.gz)
    Source code(zip)
  • v0.13.0rc1(Apr 25, 2019)

    New Features

    • Implement Server.start_serving() and related APIs. (by @jlaine in 7a4f00a3)

    • Make Server an asynchronous context manager. (by @jlaine in d6c67e7a for #221)

    Performance

    • Start using high-performance uv_udp_t handle. This should result in a significantly faster UDP support. (by @1st1 in c2b65bc8)

    • Make address validation faster in udp.sendto(). (by @1st1 in 46c5e9eb)

    Build

    • Upgrade to libuv v1.28.0.
      This is a minimum requirement now. (by @1st1 in c2b65bc8)

    • Use manylinux-2010. This means we no longer provide 32bit builds for Linux. (by @1st1 in 3174b7d3)

    Source code(tar.gz)
    Source code(zip)
  • v0.12.2(Mar 20, 2019)

    Bug Fixes

    • Fix circular references in SSL implementation to reduce the need for GC. (by @fantix in 3070ec85)

    • Fix a memory leak in call_later() and call_at(). The leak occurred when a callback argument had a reference to the event loop. (by @1st1 in 1a5dbc28 for #239)

    • Fix compilation warnings. (by @JelleZijlstra in d9a111be)

    • Round (instead of flooring) delay in call_later(). This ensures that the callback is never called slightly before the specified time. (by @fantix in 8f037a68 for #233)

    Source code(tar.gz)
    Source code(zip)
  • v0.12.1(Feb 12, 2019)

    Bug Fixes

    • Fix a circular references case in SSL implementation. (by @fantix in a2e0dd8e for #220)

    • Cleanup references to callbacks in canceled callback handles.

      This removes potential reference cycles between bound methods and cancelled Handle / TimerHandle objects.

      (by @1st1 in f0a945df)

    Source code(tar.gz)
    Source code(zip)
  • v0.12.0(Jan 21, 2019)

    New Features

    • New SSL implementation. The new implementation is faster and and more complete, and might become the default SSL implementation in asyncio 3.9.

      See the linked issue for more details.

      (by @fantix in 9cba7493 for #158, #176)

    • New uvloop.install() helper function.

      Instead of

      import asyncio
      import uvloop
      asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
      

      it is now possible to simply write

      import uvloop
      uvloop.install()
      

      (by @1st1 in a3d8d401)

    Bug Fixes

    • All bug fixes from 0.11.00.11.3 are included in this release.

    • ssl.CertificateError is no longer logged as it's delivered to the Protocol.connection_lost() anyways. (by @fantix in 848e4785 for #195, #199)

    • Don't use non-existent UDPTransport._address attribute. (by @jlaine in f24c2c56 for #207)

    Performance

    • Improve UDPTransport.sendto() performance. (by @jlaine in d5ad2b86 for #214)

    Build

    • Upgrade Cython 0.28.x -> 0.29.0.

    • Upgrade libuv v1.22.0 -> v1.23.0.

    Source code(tar.gz)
    Source code(zip)
  • v0.12.0rc1(Nov 1, 2018)

    New Features

    • New SSL implementation. The new implementation is faster and and more complete, and will become the default SSL implementation in asyncio 3.8. This is a significant change that warrants a release candidate to make sure it is tested properly.

      See the linked issue for more details.

      (by @fantix in 9cba7493 for #158, #176)

    • New uvloop.install() helper function.

      Instead of

      import asyncio
      import uvloop
      asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
      

      it is now possible to simply write

      import uvloop
      uvloop.install()
      

      (by @1st1 in a3d8d401)

    Bug Fixes

    • All bug fixes from 0.11.00.11.3 are included in this release.

    • ssl.CertificateError is no longer logged as it's delivered to the Protocol.connection_lost() anyways. (by @fantix in 848e4785 for #195, #199)

    Build

    • Upgrade Cython 0.28.x -> 0.29.0.

    • Upgrade libuv v1.22.0 -> v1.23.0.

    Source code(tar.gz)
    Source code(zip)
  • v0.11.3(Oct 31, 2018)

    Bug Fixes

    • Use new PyOS_BeforeFork and PyOS_AfterFork_* 3.7 APIs when available (by @1st1 in 75e7c32a)

    • Fix async generators finalization to function correctly in debug mode (by @1st1 in dcbb1f4f for #200)

    • Pass backlog to loop.create_unix_server() when a server is created via loop.create_server(sock=unix_sock, backlog=backlog). (by @hikoz in 40ad257b)

    • Don't raise "requires a DNS lookup" error on Unix Domain Socket (#204) (by @pax0r in 9fc3ca2a for #204)

    • Fix use of PyContext* APIs in 3.7.1 (by @1st1 in 74748005)

    Build

    • Bump Cython to 0.28.5 (by @1st1 in 1bbd6a82)
    Source code(tar.gz)
    Source code(zip)
  • v0.11.2(Aug 7, 2018)

  • v0.10.3(Aug 7, 2018)

    Note: this is a bugfix release for 0.10.x branch. It's recommended to upgrade to 0.11.x.

    Bug Fixes

    • Fix a memory leak in contextvars support. (https://github.com/MagicStack/uvloop/pull/192 for more details)
    Source code(tar.gz)
    Source code(zip)
  • v0.11.1(Aug 2, 2018)

    Bug Fixes

    • Fix server to shutdown when alive connections exist (by @ciscorn in 5f71e29f for #180 in PR #181)

    • Fix a few bugs and crashes in UDP layer (by @1st1 in e0b5ea03, 5eef2d5f for #190)

    • Fix FD leakage if spawning a subprocess fails (by @1st1 in 4f6621eb for #185, #186)

    • Fix libuv process handles leak when uv_spawn() fails (by @1st1 in 92ea5179 for #187)

    Source code(tar.gz)
    Source code(zip)
  • v0.11.0(Jul 5, 2018)

    New Features

    • Implement support for BufferedProtocol. (by @1st1 in a959f274, 76b34bef, f9c43937)

    • Implement loop.start_tls(). (by @1st1 in 622ed9c5)

    • Add Server.get_loop(). (by @1st1 in 6a42f841)

    Bug Fixes

    • Fix Server to wait in wait_closed() until all transports are done. (by @1st1 in 124e981b)

    • SSLTransport.abort() should mark the transport as closed. (by @1st1 in 4d6621f7)

    • Fix 3.7 32bit builds. (by @1st1 in a68f3c9a, b5b4abb1 for #172)

    Build

    • setup.py: Detect if the libuv submodule has not been checked out. (by @1st1 in a190cddb)

    • Fix race between futures cancellation and loop.remove_reader() / loop.remove_writer(). (by @andr-04 and @1st1 in cb0a65ae for #169)

    • Enable 3.7 CI on Travis and build wheels for 3.7. (by @1st1 in 37f964b7 for #179)

    Source code(tar.gz)
    Source code(zip)
  • v0.10.2(Jun 25, 2018)

    Bug Fixes

    • Use a proper type for the thread indent (fixes 32-bit build for 3.7.) (by @1st1 in 700582a9 for #172)

    • Fix cancellation race in loop.sock_recv() and loop.sock_recv_into() methods. (by @andr-04 and @1st1 in 298851bf for #169)

    • Sync SSL error messages with CPython's SSL implementation. (by @1st1 in c3aeff2a)

    • Fix SSLTransport.abort() to mark the transport as closed. (by @1st1 in ba25d8be)

    • Detect if libuv submodule has not been checked out in setup.py. (by @1st1 in dd8060d2)

    Source code(tar.gz)
    Source code(zip)
  • v0.10.1(Jun 1, 2018)

    Bug Fixes

    • Bump Cython from 0.28.2 to 0.28.3. (by @1st1 in 5044d240)

    • Increase default SSL handshake timeout to 60 seconds. (by @1st1 in 70c332cf, fixes #161)

    • Add ssl_handshake_timeout parameter to loop.create_connection(), loop.create_server(), loop.create_unix_connection(), loop.create_unix_server(), loop.connect_accepted_socket(). (by @1st1 in 68dd7337, addresses #161)

    • Consistently close transports if create_server/create_connection/etc timeout or cancelled. (by @1st1 in ac90d8bd and 77ee4f96)

    Source code(tar.gz)
    Source code(zip)
  • v0.10.0(May 30, 2018)

    New Features

    • Initial support for Python 3.7. (by @pfreixes in c3a5ec8e for #138)

    • Implement PEP 567 support (contextvars module) for Python 3.7. (by @1st1 in 2a4fab44, 878e4163, and b2bdaae3 for #155)

    • Add uvloop's own version of asyncio/sslproto.py. SSL is now ~50% faster. (by @1st1 in 4d912643)

    • Convert Future-returning loop methods to coroutines to match asyncio 3.7. (by @1st1 in 7384b22f)

    • Allow file objects to be passed to loop.subprocess*() functions. (by @1st1 in f0830901 for #136)

    • Make signals processing more reliable. (by @1st1 in 6e03e513)

    • Prohibit adding a signal handler for SIGCHLD. (by @1st1 in cd53b7f5 for #156)

    • Add uvloop.__version__. (by @1st1 in 740cb7f3 for #137)

    Bug Fixes

    • Upgrade to Cython 0.28.2. (by @1st1 in 98bdb553 for #122)

    • Update libuv from v1.17.0 to v1.20.3. (by @1st1 in 572524a6)

    • Make sure UDP handles are cleaned-up properly. (by @1st1 in 13f63e00)

    • Fix subprocess.close() to let its processes die gracefully. (by @1st1 in a78e4d27 and a455af3d for #128)

    • Fix sock_connect() to resolve addresses for correct socket family. (by @1st1 in ce2bd4fb for #139)

    • Fix a race condition in SSL handshake. (by @1st1 in 447e124f)

    Source code(tar.gz)
    Source code(zip)
  • v0.9.1(Nov 29, 2017)

    • Stop using malloc for uv_request* handlers.

    • Fix loop.add_reader(), loop.add_writer(), loop.remove_reader(), and loop.remove_writer() to better track socket objects.

    • Fix loop.sock_recv(), loop.sock_sendall(), loop.sock_recv_into(), and loop.sock_connect() to correctly handle Task.cancel().

    • Better handle immediate cancellation of loop.create_connection().

    • Make unit tests stricter: ensure loop.call_exception_handler() does not get called, unless it's expected.

    Source code(tar.gz)
    Source code(zip)
  • v0.9.0(Nov 27, 2017)

    TCP & UDP Transports

    • transport.get_extra_info('socket') now returns a socket-like object. It supports socket methods like setsockopts(), but prohibits send(), recv(), close() and any other calls that can interfere with the transport that ultimately owns this file descriptor.

    • TCP_NODELAY is used by default for all TCP connections.

    • Make Transport.resume_reading() and pause_reading() idempotent. This will match asyncio in Python 3.7. Issue #93.

    • loop.create_server() keeps a strong reference to the Server object it returns until its closed. Fixes #81.

    • Fix loop.connect_accepted_socket() to return correct SSL transport.

    • The UDP transport layer was rewritten from scratch. Now it uses uv_poll_* libuv APIs, instead of high-level uv_udp_* ones. This could mean a slight performance regression, and will be reverted when we port uvloop to Windows. For now this is the only viable option to make uvloop fully compatible with asyncio. When libuv gets an API to connect UDP sockets, uv_udp_connect(), we'll be able to switch to a better UDP implementation. Issue #109.

    • UDPTransport.sendto(data, addr) will raise an exception if addr requires a name resolution. Issue #91.

    Low-level sockets

    • loop.add_reader() and loop.add_writer() accept file-like objects. Issue #97.

    • loop.sock_connect() supports 4 element address tuples for IPv6 sockets. Issue #99.

    • Protect sockets from closing while they are in use by loop.sock_*() methods. Close all reader/writer sockets the loop owns when it closes. Issue #100.

    Other event loop APIs

    • loop.run_until_complete() cleans up done callbacks in all situations. By @jimmylai. See also Python issue: https://bugs.python.org/issue30423.

    • New uv_loop_fork() libuv API is used in loop.subprocess_shell() and loop.subprocess_exec() making them more stable. Issue #39.

    • loop.call_later() accepts infinite time float('inf'). Issue #102.

    • loop.subprocess_exec() accepts pathlib.Path objects for its cwd parameter. Issue #90.

    • Support pathlib.Path objects in loop.create_unix_connection() and loop.create_unix_server().

    • Try removing existing stale Unix socket paths in loop.create_unix_server().

    • ascii encoding is tried before encoding with idna. Issue #95.

    • Fix slow_callback_duration repr in warnings for callback handles and Tasks. Issue #103.

    Python 3.7

    Some APIs that will be available in Python 3.7 in vanilla asyncio, but can be used with uvloop today.

    • Implement .cancelled() method for callback and timer handles.

    • Add Transport.is_reading().

    • Implement loop.sock_recv_into().

    • Python 3.7.0a1 is now supported. Issue #110.

    Miscellaneous

    • Drop custom uvloop Future and Task implementations. This means that there will be a tiny performance regression for Python 3.5 deploys.

    • Limit stack traces in debug mode to make it faster.

    • signal.siginterrupt is now used by signals machinery to let system calls to be repeated by default, instead of raising an EINTR.

    Build

    • libuv in uvloop has been upgraded from v1.11.0 to v1.17.0. Aside from bug fixes and performance improvements, libuv survives fork.

    • LIBUV_CONFIGURE_HOST environment variable can be used to cross-compile uvloop/libuv. By @cmcqueen, for issue #104.

    • Cyhton was upgraded from 0.25.2 to 0.27.3.

    • uvloop binary is linked with pthread. By @frederikaalund, for issue #87.

    Source code(tar.gz)
    Source code(zip)
Owner
magicstack
Any sufficiently advanced software is indistinguishable from magic.
magicstack
🌀 Pykka makes it easier to build concurrent applications.

🌀 Pykka Pykka makes it easier to build concurrent applications. Pykka is a Python implementation of the actor model. The actor model introduces some

Stein Magnus Jodal 1.1k Dec 30, 2022
rosny is a lightweight library for building concurrent systems.

rosny is a lightweight library for building concurrent systems. Installation Tested on: Linux Python = 3.6 From pip: pip install rosny From source: p

Ruslan Baikulov 6 Oct 05, 2021
Python Multithreading without GIL

Multithreaded Python without the GIL

Sam Gross 2.3k Jan 05, 2023
A Python package for easy multiprocessing, but faster than multiprocessing

MPIRE, short for MultiProcessing Is Really Easy, is a Python package for multiprocessing, but faster and more user-friendly than the default multiprocessing package.

753 Dec 29, 2022
SCOOP (Scalable COncurrent Operations in Python)

SCOOP (Scalable COncurrent Operations in Python) is a distributed task module allowing concurrent parallel programming on various environments, from h

Yannick Hold 573 Dec 27, 2022
Trio – a friendly Python library for async concurrency and I/O

Trio – a friendly Python library for async concurrency and I/O The Trio project aims to produce a production-quality, permissively licensed, async/awa

5k Jan 07, 2023
aiomisc - miscellaneous utils for asyncio

aiomisc - miscellaneous utils for asyncio Miscellaneous utils for asyncio. The complete documentation is available in the following languages: English

aiokitchen 295 Jan 08, 2023
Ultra fast asyncio event loop.

uvloop is a fast, drop-in replacement of the built-in asyncio event loop. uvloop is implemented in Cython and uses libuv under the hood. The project d

magicstack 9.1k Jan 07, 2023
Jug: A Task-Based Parallelization Framework

Jug: A Task-Based Parallelization Framework Jug allows you to write code that is broken up into tasks and run different tasks on different processors.

Luis Pedro Coelho 387 Dec 21, 2022
A curated list of awesome Python asyncio frameworks, libraries, software and resources

Awesome asyncio A carefully curated list of awesome Python asyncio frameworks, libraries, software and resources. The Python asyncio module introduced

Timo Furrer 3.8k Jan 08, 2023
A concurrent sync tool which works with multiple sources and targets.

Concurrent Sync A concurrent sync tool which works similar to rsync. It supports syncing given sources with multiple targets concurrently. Requirement

Halit Şimşek 2 Jan 11, 2022
Unsynchronize asyncio by using an ambient event loop, or executing in separate threads or processes.

unsync Unsynchronize asyncio by using an ambient event loop, or executing in separate threads or processes. Quick Overview Functions marked with the @

Alex Sherman 802 Dec 28, 2022
AnyIO is an asynchronous networking and concurrency library that works on top of either asyncio or trio.

AnyIO is an asynchronous networking and concurrency library that works on top of either asyncio or trio. It implements trio-like structured concurrenc

Alex Grönholm 1.1k Jan 06, 2023
Simple package to enhance Python's concurrent.futures for memory efficiency

future-map is a Python library to use together with the official concurrent.futures module.

Arai Hiroki 2 Nov 15, 2022
Thread-safe asyncio-aware queue for Python

Mixed sync-async queue, supposed to be used for communicating between classic synchronous (threaded) code and asynchronous

aio-libs 665 Jan 03, 2023
Backport of the concurrent.futures package to Python 2.6 and 2.7

This is a backport of the concurrent.futures standard library module to Python 2. It does not work on Python 3 due to Python 2 syntax being used in th

Alex Grönholm 224 Nov 07, 2022
Raise asynchronous exceptions in other thread, control the timeout of blocks or callables with a context manager or a decorator

stopit Raise asynchronous exceptions in other threads, control the timeout of blocks or callables with two context managers and two decorators. Attent

Gilles Lenfant 97 Oct 12, 2022
A lightweight (serverless) native python parallel processing framework based on simple decorators and call graphs.

A lightweight (serverless) native python parallel processing framework based on simple decorators and call graphs, supporting both control flow and dataflow execution paradigms as well as de-centrali

102 Jan 06, 2023
Parallelformers: An Efficient Model Parallelization Toolkit for Deployment

Parallelformers: An Efficient Model Parallelization Toolkit for Deployment

TUNiB 559 Dec 28, 2022