-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repeated creation of ProcessPoolExecutor leads to "Too many open files" #124706
Comments
I can reproduce the issue by setting the maximum number of open files using |
If I understand correctly, we rely on the garbage collector to close the files fast enough? Is this correct? Shouldn't the closing of the files be handled by the library manually? |
Yes, what I'd expect to happen is that when each ProcessPoolExecutor created in my loop loses its last reference, all resources associated with it get destroyed, and therefore the number of file descriptors (or whatever other resources) in use by the program stays the same across iterations of the loop. |
If you want to release the resources applied by each
In these ways, the error would not occur, and I believe the |
In terms of why |
Bug report
Bug description:
Running this code:
Results (most of the time) in an error indicating the system has run out of file descriptors, for example:
The exact error varies. For example, one time the error happened on an
os.getcwd()
call. One time one of the futures printed as<Future at 0x1035b9950 state=finished raised PicklingError>
.I originally encountered this in the CI for Black, where it only happened on MacOS in 3.13, but the code sample above raises errors on 3.11 and 3.12 too when I run it locally. Still, it's possible that the GC changes in 3.13 make the problem more frequent.
Adding
gc.collect()
to the loop body fixes the problem. This suggests there is some cycle involving the executor that isn't getting collected until the GC kicks in.CPython versions tested on:
3.11, 3.12, 3.13
Operating systems tested on:
macOS
The text was updated successfully, but these errors were encountered: