19
19
from ... import logging , config
20
20
from ...utils .misc import is_container , rgetcwd
21
21
from ...utils .filemanip import md5 , hash_infile
22
- from ...utils .profiler import ResourceMonitor , ResourceMonitorMock
22
+ from ...utils .profiler import ResourceMonitor
23
23
24
24
iflogger = logging .getLogger ("nipype.interface" )
25
25
@@ -44,13 +44,13 @@ def __call__(self, interface, cwd=None, redirect_x=False):
44
44
if cwd is None :
45
45
cwd = _syscwd
46
46
47
- _proc_pid = os . getpid ()
48
- _ResourceMonitor = ResourceMonitor if self . _resmon else ResourceMonitorMock
49
- self ._resmon = _ResourceMonitor (
50
- _proc_pid ,
51
- cwd = cwd ,
52
- freq = float (config .get ("execution" , "resource_monitor_frequency" , 1 )),
53
- )
47
+ if self . _resmon :
48
+ _proc_pid = os . getpid ()
49
+ self ._resmon = ResourceMonitor (
50
+ _proc_pid ,
51
+ cwd = cwd ,
52
+ freq = float (config .get ("execution" , "resource_monitor_frequency" , 1 )),
53
+ )
54
54
55
55
self ._runtime = Bunch (
56
56
cwd = str (cwd ),
@@ -62,7 +62,7 @@ def __call__(self, interface, cwd=None, redirect_x=False):
62
62
platform = platform .platform (),
63
63
prevcwd = str (_syscwd ),
64
64
redirect_x = redirect_x ,
65
- resmon = self ._resmon . fname or "off" ,
65
+ resmon = getattr ( self ._resmon , " fname" , "off" ) ,
66
66
returncode = None ,
67
67
startTime = None ,
68
68
version = interface .version ,
@@ -75,7 +75,8 @@ def __enter__(self):
75
75
self ._runtime .environ ["DISPLAY" ] = config .get_display ()
76
76
77
77
self ._runtime .startTime = dt .isoformat (dt .utcnow ())
78
- self ._resmon .start ()
78
+ if self ._resmon :
79
+ self ._resmon .start ()
79
80
# TODO: Perhaps clean-up path and ensure it exists?
80
81
os .chdir (self ._runtime .cwd )
81
82
return self ._runtime
@@ -88,8 +89,9 @@ def __exit__(self, exc_type, exc_value, exc_tb):
88
89
timediff .days * 86400 + timediff .seconds + timediff .microseconds / 1e6
89
90
)
90
91
# Collect monitored data
91
- for k , v in self ._resmon .stop ().items ():
92
- setattr (self ._runtime , k , v )
92
+ if self ._resmon :
93
+ for k , v in self ._resmon .stop ().items ():
94
+ setattr (self ._runtime , k , v )
93
95
94
96
os .chdir (self ._runtime .prevcwd )
95
97
0 commit comments