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
andthreading.RLock
objects as spin locks by making them callsleep(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, sounlink
can sometimes be optimized out. See :issue:1487
.๐ Make
gevent.pywsgi
supportConnection: 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 raiseInvalidThreadUseError
whenspawn
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," orLoopExit
. On gevent 1.4, it could raiseLoopExit
, 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 withGreenlet.kill()
. See :issue:1473
reported by kochelmonster.๐ Make
gevent.spawn_raw
set theloop
attribute on returned greenlets. This lets them work with more gevent APIs, notablygevent.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 fromrb
to simplyr
, for consistency with the other file objects and the standardopen
and :func:io.open
functions.๐ Fix
FileObjectPosix
improperly being used from multiple greenlets. Previously this was hidden by forcing buffering, which raisedRuntimeError
.