Skip to content

Commit 70982b6

Browse files
authored
Merge pull request #2435 from effigies/fix/fallback_init
FIX: Fall-back to initializing workflow in main process
2 parents e31573f + 314dc39 commit 70982b6

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

fmriprep/cli/run.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,28 @@ def main():
3333
# CRITICAL Call build_workflow(config_file, retval) in a subprocess.
3434
# Because Python on Linux does not ever free virtual memory (VM), running the
3535
# workflow construction jailed within a process preempts excessive VM buildup.
36-
with Manager() as mgr:
36+
try:
37+
with Manager() as mgr:
38+
from .workflow import build_workflow
39+
40+
retval = mgr.dict()
41+
p = Process(target=build_workflow, args=(str(config_file), retval))
42+
p.start()
43+
p.join()
44+
45+
retcode = p.exitcode or retval.get("return_code", 0)
46+
fmriprep_wf = retval.get("workflow", None)
47+
except ConnectionError:
48+
config.loggers.workflow.warning(
49+
"Could not build workflow in separate process. Attempting to build "
50+
"in main process. This may impact memory footprint."
51+
)
52+
# Attempt to fall back to building in the main process
3753
from .workflow import build_workflow
38-
39-
retval = mgr.dict()
40-
p = Process(target=build_workflow, args=(str(config_file), retval))
41-
p.start()
42-
p.join()
43-
44-
retcode = p.exitcode or retval.get("return_code", 0)
45-
fmriprep_wf = retval.get("workflow", None)
54+
retval = {}
55+
build_workflow(str(config_file), retval)
56+
fmriprep_wf = retval["workflow"]
57+
retcode = 0
4658

4759
# CRITICAL Load the config from the file. This is necessary because the ``build_workflow``
4860
# function executed constrained in a process may change the config (and thus the global

0 commit comments

Comments
 (0)