This is based on upstream work here: https://github.com/python/cpython/pull/3934 and https://github.com/python/cpython/pull/39430 First patch was kept as is (just rebased) while the second was combined into one. Signed-off-by: Rosen Penev <rosenp@gmail.com>