Skip to content

Commit 4b17465

Browse files
authored
fix: revise configuration of resource monitor at the interface level
1 parent 064bd4b commit 4b17465

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

nipype/interfaces/base/core.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class BaseInterface(Interface):
173173
_additional_metadata = []
174174
_redirect_x = False
175175
_references = []
176-
resource_monitor = True # Enabled for this interface IFF enabled in the config
176+
resource_monitor = None # Enabled for this interface IFF enabled in the config
177177
_etelemetry_version_data = None
178178

179179
def __init__(
@@ -202,9 +202,10 @@ def __init__(
202202
self.inputs.trait_set(**inputs)
203203

204204
self.ignore_exception = ignore_exception
205-
206-
if resource_monitor is not None:
207-
self.resource_monitor = resource_monitor
205+
self.resource_monitor = (
206+
resource_monitor if resource_monitor is not None
207+
else config.resource_monitor
208+
)
208209

209210
if from_file is not None:
210211
self.load_inputs_from_json(from_file, overwrite=True)
@@ -376,18 +377,13 @@ def run(self, cwd=None, ignore_exception=None, **inputs):
376377
if successful, results
377378
378379
"""
379-
rtc = RuntimeContext(
380-
resource_monitor=config.resource_monitor and self.resource_monitor,
381-
ignore_exception=ignore_exception
382-
if ignore_exception is not None
383-
else self.ignore_exception,
384-
)
385380

386381
with indirectory(cwd or os.getcwd()):
387382
self.inputs.trait_set(**inputs)
388383
self._check_mandatory_inputs()
389384
self._check_version_requirements(self.inputs)
390385

386+
rtc = RuntimeContext()
391387
with rtc(self, cwd=cwd, redirect_x=self._redirect_x) as runtime:
392388

393389
# Grab inputs now, as they should not change during execution

nipype/interfaces/base/support.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,21 @@ class RuntimeContext(AbstractContextManager):
3131

3232
__slots__ = ("_runtime", "_resmon", "_ignore_exc")
3333

34-
def __init__(self, resource_monitor=False, ignore_exception=False):
34+
def __init__(self):
3535
"""Initialize the context manager object."""
36-
self._ignore_exc = ignore_exception
37-
self._resmon = resource_monitor
36+
self._ignore_exc = False
37+
self._resmon = None
3838

3939

40-
def __call__(self, interface, cwd=None, redirect_x=False):
40+
def __call__(self, interface, cwd=None, redirect_x=False, ignore_exception=False):
4141
"""Generate a new runtime object."""
4242
# Tear-up: get current and prev directories
4343
_syscwd = rgetcwd(error=False) # Recover when wd does not exist
4444
if cwd is None:
4545
cwd = _syscwd
4646

47-
if self._resmon:
47+
self._ignore_exc = ignore_exception or interface.ignore_exception
48+
if interface.resource_monitor is True:
4849
_proc_pid = os.getpid()
4950
self._resmon = ResourceMonitor(
5051
_proc_pid,

0 commit comments

Comments
 (0)