-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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 generates FileNotFoundError when argument isn't explicitly referenced #94765
Comments
Confirmed the issue on Python 3.9 and 3.12 on MacOS 11.5.2 . |
Confirmed the issue on python 3.8 on macos 13.0.1 |
Confirmed the issue on Python 3.8.16 on MacOS 13.1 (22C65). |
Same here on Ubuntu 22.04 with Python 3.10.6. File it is looking for has 777 permissions. Specifically [working_directory]/lib/tom-select/tom-select.css, a file created by pyvis v 0.3.1 by a past run of the same script. If I These errors were also very opaque, as they required a chain of try: .., except Exception as err: ... print(err) clauses to get the error to print to the console. I presume there is an issue with the pipe of stderr in this context as well. Additionally, running the process in the context of "fork" does not resolve the issue (same error). The workaround of using args = [multiprocessing.Value(...)] instead of args=(0) throws the error
As a (not ideal) workaround, I ultimately made the offending process operate under a subprocess.run() context as a parameterized script and used a Process() as a proxy between the main script and the actual process. That "worked for now". |
https://superfastpython.com/filenotfounderror-multiprocessing-python/ Тут расписано мне помог простой time.sleep(1) после p.start() |
Confirmed the issue on Python 3.9.17 on MacOS 14. |
I was having a similar issue with sharing concurrency primitives (a multiprocessing.Queue in my case) across processes when using the spawn backend. I believe this is happening because of ref counts / garbage collection. If there's a possibility the object gets deleted by the main process while/during/before being shared, the file isn't around when the other processes look for it and it is a FileNotFoundError. This explains why putting it a variable (preventing the object from being deallocated) works and explicitly putting into a progress argument does not. The object getting deleted could also happen if the main process ends too soon, as referenced in this article: https://superfastpython.com/filenotfounderror-multiprocessing-python/ |
We can reproduce this problem with the following piece of code using Python 3.8.10 on Ubuntu Linux 20.04: import multiprocessing as mp
def demo(argument):
print(argument)
def create_process():
arg = mp.Value("i", 0)
return mp.Process(target=demo, args=[arg])
if __name__ == "__main__":
mp.set_start_method("spawn") # fails
# mp.set_start_method("fork") # works
# mp.set_start_method("forkserver") # also fails
process = create_process()
process.start()
process.join() This leads to the same stacktrace as in the OP. The issue does not seem to be related to the garbage collector, as disabling it before creating the process and enabling it after Is this a bug in CPython, or are we supposed to perform these steps in a different way? |
The object gets deallocated anyway because the refcount reaches 0. That's not part of the garbage collector I think. After your create_process method finishes the value of arg gets deallocated. If you create |
Hitting this problem as well.
|
In my conda environment I'm using python=3.12.2 however I get the warning that is referring to the multiprocessing module of python 3.8. I've already double checked the python version using
To be specific I'm using pytorch multiprocessing in order to spawn multiple process for multi-GPUs training. |
Process Process-1: Is this issue on all Python 3.x versions? |
Confirmed the issue on python 3.10 on macos 14.4.1 |
time.sleep work on Ubuntu 22.04.3 on python 3.10 but still a issue. |
Confirmed the issue on Python 3.11.11 macOS Sequoia 15.3 (24D60) |
Bug report
This is a continuation for the possible bug mentioned in issue #82236 which was closed because DonnyBrown, the submitter, didn't provide enough information.
DonnyBrown was getting a FileNotFoundError when starting a process with multiprocessing.Process that uses an argument that doesn't have an explicit reference. I'm able to reproduce the same error using the test code DonnyBrown provided in that issue on Ubuntu Desktop LTS 22.04 x86-64 with CPython 3.10.4. @iritkatriel mentioned that they were unable to reproduce the error on Windows 10 with Python 3.10.
I can also reproduce the error using this slightly modified/simpler version of DonnyBrown's test code that I have been testing:
The traceback I get with the above code is:
The above code can be made to work on my test system by making any of the following changes:
I'm not a Python expert so maybe this is the expected behavior when spawning a process directly with a multiprocessing.Value but it does seem odd that making any of the above mentioned changes causes the code to work or that (based on @iritkatriel's success with DonnyBrown's test code) running it on Windows 10 (which uses the "spawn" start method) will probably cause the code to work.
Your environment
The text was updated successfully, but these errors were encountered: