gevent v1.5.a3 Release Notes

Release Date: 2020-01-01 // over 4 years ago
    • โšก๏ธ Python version updates: gevent is now tested with CPython 2.7.17, 3.5.9, 3.6.9, 3.7.5 and 3.8.0 (final). It is also tested with PyPy2 7.2 and PyPy 3.6 7.2

    • ๐Ÿ›  Fix using monkey-patched threading.Lock and threading.RLock objects as spin locks by making them call sleep(0) if they failed to acquire the lock in a non-blocking call. This lets other callbacks run to release the lock, simulating preemptive threading. Using spin locks is not recommended, but may have been done in code written for threads, especially on Python 3. See :issue:1464.

    • ๐Ÿ›  Fix Semaphore (and monkey-patched threading locks) to be fair. This eliminates the rare potential for starvation of greenlets. As part of this change, the low-level method rawlink of Semaphore, Event, and AsyncResult now always remove the link object when calling it, so unlink can sometimes be optimized out. See :issue:1487.

    • ๐Ÿ‘‰ Make gevent.pywsgi support Connection: keep-alive in HTTP/1.0. Based on :pr:1331 by tanchuhan.

    • ๐Ÿ›  Fix a potential crash using gevent.idle() when using libuv. See :issue:1489.

    • ๐Ÿ›  Fix some potential crashes using libuv async watchers.

    • ๐Ÿ‘€ Make ThreadPool consistently raise InvalidThreadUseError when spawn is called from a thread different than the thread that created the threadpool. This has never been allowed, but was inconsistently enforced. On gevent 1.3 and before, this would always raise "greenlet error: invalid thread switch," or LoopExit. On gevent 1.4, it could raise LoopExit, depending on the number of tasks, but still, calling it from a different thread was likely to corrupt libev or libuv internals.

    • โœ‚ Remove some undocumented, deprecated functions from the threadpool module.

    • libuv: Fix a perceived slowness spawning many greenlets at the same time without yielding to the event loop while having no active IO watchers or timers. If the time spent launching greenlets exceeded the switch interval and there were no other active watchers, then the default IO poll time of about .3s would elapse between spawning batches. This could theoretically apply for any non-switching callbacks. This can be produced in synthetic benchmarks and other special circumstances, but real applications are unlikely to be affected. See :issue:1493.

    • ๐Ÿ›  Fix using the threadpool inside a script or module run with python -m gevent.monkey. Previously it would use greenlets instead of native threads. See :issue:1484.

    • ๐Ÿ›  Fix potential crashes in the FFI backends if a watcher was closed and stopped in the middle of a callback from the event loop and then raised an exception. This could happen if the hub's handle_error function was poorly customized, for example. See :issue:1482

    • ๐Ÿ‘‰ Make gevent.killall stop greenlets from running that hadn't been run yet. This make it consistent with Greenlet.kill(). See :issue:1473 reported by kochelmonster.

    • ๐Ÿ‘‰ Make gevent.spawn_raw set the loop attribute on returned greenlets. This lets them work with more gevent APIs, notably gevent.killall(). They already had dictionaries, but this may make them slightly larger, depending on platform (on CPython 2.7 through 3.6 there is no apparent difference for one attribute but on CPython 3.7 and 3.8 dictionaries are initially empty and only allocate space once an attribute is added; they're still smaller than on earlier versions though).

    File Object Changes

    .. caution:: There may be breaking changes here for applications that relied on the old behaviour. The old behaviour was under specified and inconsistent and really only worked consistently with 'wb' and 'rb' modes, so most applications shouldn't be affected.

    • The file objects (FileObjectPosix, FileObjectThread) now consistently support text and binary modes. If neither 'b' nor 't' is given in the mode, they will read and write native strings. If 't' is given, they will always work with unicode strings, and 'b' will always work with byte strings. (FileObjectPosix already worked this way.) See :issue:1441.

    • The file objects accept encoding, errors and newline arguments. On Python 2, these are only used if 't' is in the mode.

    • 0๏ธโƒฃ The default mode for FileObjectPosix changed from rb to simply r, for consistency with the other file objects and the standard open and :func:io.open functions.

    • ๐Ÿ›  Fix FileObjectPosix improperly being used from multiple greenlets. Previously this was hidden by forcing buffering, which raised RuntimeError.