-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
multiprocessing.Process() with method fork() works not the same with os.fork() on unloading of .so files #127213
Comments
confirm on python 3.13 |
After testing, I found that the .so files would not be unloaded if I use os._exit() in child process created by os.fork(). |
3.11 is security only and does not accept bug fixes anymore. However your previous comments hints that the bug is still present in 3.13. |
ok,thank you |
As for whether this should be changed or not, I don't think changing os._exit() to sys.exit() is correct but I believe that multiprocessing forked processes should behave as if they were spawned using os.fork(), so I'd also expect the .so file to be unloaded by the child process when the latter dies. Is it inconvenient for the .so file to be kept alive for as long as the parent process exists? or is there some reason to close it except for freeing some resources? cc @gpshead as the mp expert |
Thank you, actually I also think that replace os._exit() to sys.exit() directly is not a good idea, but now I have not found another way to solve it. We may construct a situation that I pin a memory page by get_user_pages() or some api else with a shared_ptr defined in the dynamic library, and it will be released when the .so is unloaded by calling the dtor of shared_ptr. So if the .so is not unloaded, the pages will not be released and cause a mem leak. |
Bug report
Bug description:
I have a c/cpp file and compile it with pybind to get a so named xyz_test.cpython-311-x86_64-linux-gnu.so so that I can import it(xyz_test) and call a method named xyz_test.call() in Python code .
I use it with multiprocessing.Process() or os.fork(), but the unload process of this so is different:
The behavior with os.fork() is the same with what I test on C code with C fork(), so is the behavior a bug with multiprocessing.Process() ?
Thank you!
CPython versions tested on:
3.11
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: