Skip to content

Commit 8e710fa

Browse files
committed
address @satra's comments
1 parent a40eb3b commit 8e710fa

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

doc/users/config_file.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Logging
2424
*interface_level*
2525
How detailed the logs regarding interface execution should be (possible
2626
values: ``INFO`` and ``DEBUG``; default value: ``INFO``)
27-
*filemanip_level* (deprecated as of 0.13.2)
27+
*filemanip_level* (deprecated as of 1.0)
2828
How detailed the logs regarding file operations (for example overwriting
2929
warning) should be (possible values: ``INFO`` and ``DEBUG``)
3030
*log_to_file*
@@ -157,6 +157,7 @@ Execution
157157
*resource_monitor_frequency*
158158
Sampling period (in seconds) between measurements of resources (memory, cpus)
159159
being used by an interface. Requires ``resource_monitor`` to be ``true``.
160+
(default value: ``1``)
160161

161162
Example
162163
~~~~~~~

nipype/interfaces/base.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -732,9 +732,6 @@ class BaseInterfaceInputSpec(TraitedSpec):
732732
ignore_exception = traits.Bool(False, usedefault=True, nohash=True,
733733
desc='Print an error message instead of throwing an exception '
734734
'in case the interface fails to run')
735-
resource_monitor = traits.Bool(True, usedefault=True, nohash=True,
736-
desc='Disable the resource monitor for this interface '
737-
'(overloads the default nipype config).')
738735

739736

740737
class BaseInterface(Interface):
@@ -760,8 +757,9 @@ class BaseInterface(Interface):
760757
_additional_metadata = []
761758
_redirect_x = False
762759
references_ = []
760+
resource_monitor = True
763761

764-
def __init__(self, from_file=None, **inputs):
762+
def __init__(self, from_file=None, resource_monitor=None, **inputs):
765763
if not self.input_spec:
766764
raise Exception('No input_spec in class: %s' %
767765
self.__class__.__name__)
@@ -770,6 +768,9 @@ def __init__(self, from_file=None, **inputs):
770768
self.estimated_memory_gb = 0.25
771769
self.num_threads = 1
772770

771+
if resource_monitor is not None:
772+
self.resource_monitor = resource_monitor
773+
773774
if from_file is not None:
774775
self.load_inputs_from_json(from_file, overwrite=True)
775776

@@ -1057,7 +1058,7 @@ def run(self, **inputs):
10571058
"""
10581059
from ..utils.profiler import resource_monitor, ResourceMonitor
10591060

1060-
enable_rm = resource_monitor and getattr(self.inputs, 'resource_monitor', True)
1061+
enable_rm = resource_monitor and self.resource_monitor
10611062
force_raise = not getattr(self.inputs, 'ignore_exception', False)
10621063
self.inputs.trait_set(**inputs)
10631064
self._check_mandatory_inputs()
@@ -1081,7 +1082,7 @@ def run(self, **inputs):
10811082

10821083
mon_sp = None
10831084
if enable_rm:
1084-
mon_freq = config.get('execution', 'resource_monitor_frequency', 1)
1085+
mon_freq = float(config.get('execution', 'resource_monitor_frequency', 1))
10851086
proc_pid = os.getpid()
10861087
mon_fname = os.path.abspath('.prof-%d_freq-%0.3f' % (proc_pid, mon_freq))
10871088
iflogger.debug('Creating a ResourceMonitor on a %s interface: %s',
@@ -1159,6 +1160,7 @@ def _list_outputs(self):
11591160
def aggregate_outputs(self, runtime=None, needed_outputs=None):
11601161
""" Collate expected outputs and check for existence
11611162
"""
1163+
11621164
predicted_outputs = self._list_outputs()
11631165
outputs = self._outputs()
11641166
if predicted_outputs:
@@ -1176,15 +1178,13 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None):
11761178
self.__class__.__name__))
11771179
try:
11781180
setattr(outputs, key, val)
1179-
getattr(outputs, key)
11801181
except TraitError as error:
1181-
if hasattr(error, 'info') and \
1182-
error.info.startswith("an existing"):
1182+
if getattr(error, 'info', 'default').startswith('an existing'):
11831183
msg = ("File/Directory '%s' not found for %s output "
11841184
"'%s'." % (val, self.__class__.__name__, key))
11851185
raise FileNotFoundError(msg)
1186-
else:
1187-
raise error
1186+
raise error
1187+
11881188
return outputs
11891189

11901190
@property
@@ -1368,7 +1368,6 @@ def _process(drain=0):
13681368
while proc.returncode is None:
13691369
proc.poll()
13701370
_process()
1371-
time.sleep(0)
13721371

13731372
_process(drain=1)
13741373

@@ -1479,7 +1478,6 @@ class must be instantiated with a command argument
14791478
{'args': '-al',
14801479
'environ': {'DISPLAY': ':1'},
14811480
'ignore_exception': False,
1482-
'resource_monitor': True,
14831481
'terminal_output': 'stream'}
14841482
14851483
>>> cli.inputs.get_hashval()[0][0] # doctest: +ALLOW_UNICODE

0 commit comments

Comments
 (0)