24
24
"""fMRI preprocessing workflow."""
25
25
from .. import config
26
26
27
- EXITCODE : int = - 1
28
-
29
27
30
28
def main ():
31
29
"""Entry point."""
@@ -76,15 +74,12 @@ def main():
76
74
77
75
sentry_sdk = None
78
76
if not config .execution .notrack and not config .execution .debug :
79
- import atexit
80
-
81
77
import sentry_sdk
82
78
83
79
from ..utils .telemetry import sentry_setup , setup_migas
84
80
85
81
sentry_setup ()
86
82
setup_migas (init_ping = True )
87
- atexit .register (migas_exit )
88
83
89
84
# CRITICAL Save the config to a file. This is necessary because the execution graph
90
85
# is built as a separate process to keep the memory footprint low. The most
@@ -110,8 +105,7 @@ def main():
110
105
else :
111
106
retval = build_workflow (str (config_file ), {})
112
107
113
- global EXITCODE
114
- EXITCODE = retval .get ("return_code" , 0 )
108
+ exitcode = retval .get ("return_code" , 0 )
115
109
fmriprep_wf = retval .get ("workflow" , None )
116
110
117
111
# CRITICAL Load the config from the file. This is necessary because the ``build_workflow``
@@ -120,14 +114,14 @@ def main():
120
114
config .load (config_file )
121
115
122
116
if config .execution .reports_only :
123
- sys .exit (int (EXITCODE > 0 ))
117
+ sys .exit (int (exitcode > 0 ))
124
118
125
119
if fmriprep_wf and config .execution .write_graph :
126
120
fmriprep_wf .write_graph (graph2use = "colored" , format = "svg" , simple_form = True )
127
121
128
- EXITCODE = EXITCODE or (fmriprep_wf is None ) * EX_SOFTWARE
129
- if EXITCODE != 0 :
130
- sys .exit (EXITCODE )
122
+ exitcode = exitcode or (fmriprep_wf is None ) * EX_SOFTWARE
123
+ if exitcode != 0 :
124
+ sys .exit (exitcode )
131
125
132
126
# Generate boilerplate
133
127
with Manager () as mgr :
@@ -138,7 +132,7 @@ def main():
138
132
p .join ()
139
133
140
134
if config .execution .boilerplate_only :
141
- sys .exit (int (EXITCODE > 0 ))
135
+ sys .exit (int (exitcode > 0 ))
142
136
143
137
# Clean up master process before running workflow, which may create forks
144
138
gc .collect ()
@@ -238,37 +232,6 @@ def main():
238
232
sys .exit (int ((errno + failed_reports ) > 0 ))
239
233
240
234
241
- def migas_exit () -> None :
242
- """
243
- Send a final crumb to the migas server signaling if the run successfully completed
244
- This function should be registered with `atexit` to run at termination.
245
- """
246
- import sys
247
-
248
- from ..utils .telemetry import send_breadcrumb
249
-
250
- global EXITCODE
251
- migas_kwargs = {'status' : 'C' }
252
- # `sys` will not have these attributes unless an error has been handled
253
- if hasattr (sys , 'last_type' ):
254
- migas_kwargs = {
255
- 'status' : 'F' ,
256
- 'status_desc' : 'Finished with error(s)' ,
257
- 'error_type' : sys .last_type ,
258
- 'error_desc' : sys .last_value ,
259
- }
260
- elif EXITCODE != 0 :
261
- migas_kwargs .update (
262
- {
263
- 'status' : 'F' ,
264
- 'status_desc' : f'Completed with exitcode { EXITCODE } ' ,
265
- }
266
- )
267
- else :
268
- migas_kwargs ['status_desc' ] = 'Success'
269
- send_breadcrumb (** migas_kwargs )
270
-
271
-
272
235
if __name__ == "__main__" :
273
236
raise RuntimeError (
274
237
"fmriprep/cli/run.py should not be run directly;\n "
0 commit comments