@@ -732,9 +732,6 @@ class BaseInterfaceInputSpec(TraitedSpec):
732
732
ignore_exception = traits .Bool (False , usedefault = True , nohash = True ,
733
733
desc = 'Print an error message instead of throwing an exception '
734
734
'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).' )
738
735
739
736
740
737
class BaseInterface (Interface ):
@@ -760,8 +757,9 @@ class BaseInterface(Interface):
760
757
_additional_metadata = []
761
758
_redirect_x = False
762
759
references_ = []
760
+ resource_monitor = True
763
761
764
- def __init__ (self , from_file = None , ** inputs ):
762
+ def __init__ (self , from_file = None , resource_monitor = None , ** inputs ):
765
763
if not self .input_spec :
766
764
raise Exception ('No input_spec in class: %s' %
767
765
self .__class__ .__name__ )
@@ -770,6 +768,9 @@ def __init__(self, from_file=None, **inputs):
770
768
self .estimated_memory_gb = 0.25
771
769
self .num_threads = 1
772
770
771
+ if resource_monitor is not None :
772
+ self .resource_monitor = resource_monitor
773
+
773
774
if from_file is not None :
774
775
self .load_inputs_from_json (from_file , overwrite = True )
775
776
@@ -1057,7 +1058,7 @@ def run(self, **inputs):
1057
1058
"""
1058
1059
from ..utils .profiler import resource_monitor , ResourceMonitor
1059
1060
1060
- enable_rm = resource_monitor and getattr ( self .inputs , ' resource_monitor' , True )
1061
+ enable_rm = resource_monitor and self .resource_monitor
1061
1062
force_raise = not getattr (self .inputs , 'ignore_exception' , False )
1062
1063
self .inputs .trait_set (** inputs )
1063
1064
self ._check_mandatory_inputs ()
@@ -1081,7 +1082,7 @@ def run(self, **inputs):
1081
1082
1082
1083
mon_sp = None
1083
1084
if enable_rm :
1084
- mon_freq = config .get ('execution' , 'resource_monitor_frequency' , 1 )
1085
+ mon_freq = float ( config .get ('execution' , 'resource_monitor_frequency' , 1 ) )
1085
1086
proc_pid = os .getpid ()
1086
1087
mon_fname = os .path .abspath ('.prof-%d_freq-%0.3f' % (proc_pid , mon_freq ))
1087
1088
iflogger .debug ('Creating a ResourceMonitor on a %s interface: %s' ,
@@ -1159,6 +1160,7 @@ def _list_outputs(self):
1159
1160
def aggregate_outputs (self , runtime = None , needed_outputs = None ):
1160
1161
""" Collate expected outputs and check for existence
1161
1162
"""
1163
+
1162
1164
predicted_outputs = self ._list_outputs ()
1163
1165
outputs = self ._outputs ()
1164
1166
if predicted_outputs :
@@ -1176,15 +1178,13 @@ def aggregate_outputs(self, runtime=None, needed_outputs=None):
1176
1178
self .__class__ .__name__ ))
1177
1179
try :
1178
1180
setattr (outputs , key , val )
1179
- getattr (outputs , key )
1180
1181
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' ):
1183
1183
msg = ("File/Directory '%s' not found for %s output "
1184
1184
"'%s'." % (val , self .__class__ .__name__ , key ))
1185
1185
raise FileNotFoundError (msg )
1186
- else :
1187
- raise error
1186
+ raise error
1187
+
1188
1188
return outputs
1189
1189
1190
1190
@property
@@ -1368,7 +1368,6 @@ def _process(drain=0):
1368
1368
while proc .returncode is None :
1369
1369
proc .poll ()
1370
1370
_process ()
1371
- time .sleep (0 )
1372
1371
1373
1372
_process (drain = 1 )
1374
1373
@@ -1479,7 +1478,6 @@ class must be instantiated with a command argument
1479
1478
{'args': '-al',
1480
1479
'environ': {'DISPLAY': ':1'},
1481
1480
'ignore_exception': False,
1482
- 'resource_monitor': True,
1483
1481
'terminal_output': 'stream'}
1484
1482
1485
1483
>>> cli.inputs.get_hashval()[0][0] # doctest: +ALLOW_UNICODE
0 commit comments