Skip to content
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 RuntimeError #192

Open
MAX22110 opened this issue Jul 7, 2022 · 13 comments
Open

Multiprocessing RuntimeError #192

MAX22110 opened this issue Jul 7, 2022 · 13 comments

Comments

@MAX22110
Copy link

MAX22110 commented Jul 7, 2022

Running my code, I am given the following error:

File "", line 1, in
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/multiprocessing/spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/multiprocessing/spawn.py", line 125, in _main
prepare(preparation_data)
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/multiprocessing/spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/runpy.py", line 268, in run_path
return _run_module_code(code, init_globals, run_name,
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/Max/Data_Analysis/StrongPipeline4.py", line 1408, in
result_7 = search.fit(model=model, analysis=analysis_6)
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/site-packages/autofit/non_linear/abstract_search.py", line 489, in fit
self._fit(model=model, analysis=analysis, log_likelihood_cap=log_likelihood_cap)
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/site-packages/autofit/non_linear/nest/dynesty/abstract.py", line 145, in _fit
pool = self.make_sneaky_pool(
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/site-packages/autofit/non_linear/abstract_search.py", line 64, in wrapper
return func(self, *args, **kwargs)
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/site-packages/autofit/non_linear/abstract_search.py", line 730, in make_sneaky_pool
return SneakyPool(
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/site-packages/autofit/non_linear/parallel/sneaky.py", line 256, in init
process.start()
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/multiprocessing/process.py", line 121, in start
self._popen = self._Popen(self)
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/multiprocessing/context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
return Popen(process_obj)
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in init
super().init(process_obj)
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/multiprocessing/popen_fork.py", line 19, in init
self._launch(process_obj)
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 42, in _launch
prep_data = spawn.get_preparation_data(process_obj._name)
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/multiprocessing/spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "/Users/Max/miniconda3/envs/autolens/lib/python3.9/multiprocessing/spawn.py", line 134, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if name == 'main':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.

I am working with the Python version 3.9 and I'm running the code on remote machine through ssh.
The remote machine is a Mac.

@rhayes777
Copy link
Collaborator

Hi Max. Could you try putting your code in a function or using if __name__ == "__main__"?

Something like:

if __name__ == "__main__":
    # your code goes here.

@MAX22110
Copy link
Author

MAX22110 commented Jul 8, 2022

Yes, I’m going to try

@MAX22110
Copy link
Author

MAX22110 commented Jul 8, 2022

It seems the fitting procedure has been started successfully, it's running. I've used
if name == "main":
# your code goes here.

@rhayes777
Copy link
Collaborator

rhayes777 commented Jul 8, 2022 via email

@MAX22110
Copy link
Author

MAX22110 commented Jul 8, 2022

Do you mean the module spawn.py?

@Jammy2211
Copy link
Owner

@rhayes777 Any advise for how I should build this into example scripts to ensure it doesnt crop up again? Would be annoying to have extra lines of code (e.g. if name == "main") in every script.

@rhayes777
Copy link
Collaborator

I don't think there is anyway to avoid this exception on MacOS doing multiprocessing without that check. I'll have a dig just in case.

@MAX22110
Copy link
Author

Hi, I’m afraid (though I’m not sure this is the true reason) there is some problem with the solution you have found.
In fact whenever I launch the script with that command you suggested, I’m leaved with tons of background python multiprocessing running process and this gives me an out of memory problem. I have to kill all of them manually. I repeat, I don’t know if the reason is that command, but I’ve never had this problem before.

@Jammy2211
Copy link
Owner

@rhayes777 I think we need to stress-test parallelization of multiple PYthon versions (3.6 -> 3.9) and for different numpy / numba versions.

I suspect this issue hasnt cropped up before because I am used to using 3.6.

@rhayes777
Copy link
Collaborator

rhayes777 commented Jul 12, 2022 via email

@MAX22110
Copy link
Author

MAX22110 commented Jul 12, 2022

Files.zip

@Jammy2211
Copy link
Owner

They are on numpy==1.21.5, and I think numpy threading could be the cause of this (Albeit it could be a separate issue with multiprocessing + dynesty).

@Jammy2211
Copy link
Owner

Also on Linux (windows subsystem for linux techncially)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants