PyAutoLens icon indicating copy to clipboard operation
PyAutoLens copied to clipboard

Multiprocessing RuntimeError

Open MAX22110 opened this issue 3 years ago • 13 comments

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.

MAX22110 avatar Jul 07 '22 21:07 MAX22110

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.

rhayes777 avatar Jul 08 '22 14:07 rhayes777

Yes, I’m going to try

MAX22110 avatar Jul 08 '22 15:07 MAX22110

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

MAX22110 avatar Jul 08 '22 15:07 MAX22110

Great! I think if you don't use the main check then the module gets imported when the new process starts causing a recursion.

On Fri, 8 Jul 2022, 16:51 MAX22110, @.***> wrote:

It seems the fitting procedure has been started successfully, it's running

— Reply to this email directly, view it on GitHub https://github.com/Jammy2211/PyAutoLens/issues/192#issuecomment-1179139156, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQRGMQU2AR73Y3EH6YFZ7TVTBFBZANCNFSM526YUPGQ . You are receiving this because you commented.Message ID: @.***>

rhayes777 avatar Jul 08 '22 16:07 rhayes777

Do you mean the module spawn.py?

MAX22110 avatar Jul 08 '22 17:07 MAX22110

@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.

Jammy2211 avatar Jul 09 '22 09:07 Jammy2211

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.

rhayes777 avatar Jul 10 '22 09:07 rhayes777

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.

MAX22110 avatar Jul 12 '22 09:07 MAX22110

@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.

Jammy2211 avatar Jul 12 '22 09:07 Jammy2211

Could you see me your script so I can try to replicate the issue?

On Tue, 12 Jul 2022, 10:27 MAX22110, @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/Jammy2211/PyAutoLens/issues/192#issuecomment-1181534406, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQRGMSD6JRN7IMXACVAIM3VTU27RANCNFSM526YUPGQ . You are receiving this because you were mentioned.Message ID: @.***>

rhayes777 avatar Jul 12 '22 09:07 rhayes777

Files.zip

MAX22110 avatar Jul 12 '22 09:07 MAX22110

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 avatar Jul 12 '22 10:07 Jammy2211

Also on Linux (windows subsystem for linux techncially)

Jammy2211 avatar Jul 12 '22 10:07 Jammy2211