Use os.closerange instead of counting to 1 billion
In billiard.compat.close_open_fds, after checking whether os.closerange exists, if it exists we did not use it, which makes no sense at all.
Instead, the implementation called os.close, os.sysconf("SC_OPENMAX") - len(keep) times.
On most systems, SC_OPENMAX is something like 1024, 4096, or 65536. In the latter case, calling it will already take 30ms on my system, almost noticable for humans.
But docker (and some systems) uses a really high value:
docker run --rm python python -c 'import os;print(os.sysconf("SC_OPEN_MAX"))'
1073741816
In other words, when running in docker we were counting to 1 billlion, at 2 million per second.
The single function call close_open_fd([0,1,2]) takes almost 10 minutes there!
The fix is trivial: When os.closerange is available, use the existing implementation. It's right there!
An alternative approach would be to just list all open handles with psutil.Process().open_files() or so, and then just close those few.