Skip to content

Commit 064bd4b

Browse files
authored
fix: do not use mock
1 parent 1fcc082 commit 064bd4b

File tree

2 files changed

+14
-30
lines changed

2 files changed

+14
-30
lines changed

nipype/interfaces/base/support.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from ... import logging, config
2020
from ...utils.misc import is_container, rgetcwd
2121
from ...utils.filemanip import md5, hash_infile
22-
from ...utils.profiler import ResourceMonitor, ResourceMonitorMock
22+
from ...utils.profiler import ResourceMonitor
2323

2424
iflogger = logging.getLogger("nipype.interface")
2525

@@ -44,13 +44,13 @@ def __call__(self, interface, cwd=None, redirect_x=False):
4444
if cwd is None:
4545
cwd = _syscwd
4646

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+
)
5454

5555
self._runtime = Bunch(
5656
cwd=str(cwd),
@@ -62,7 +62,7 @@ def __call__(self, interface, cwd=None, redirect_x=False):
6262
platform=platform.platform(),
6363
prevcwd=str(_syscwd),
6464
redirect_x=redirect_x,
65-
resmon=self._resmon.fname or "off",
65+
resmon=getattr(self._resmon, "fname", "off"),
6666
returncode=None,
6767
startTime=None,
6868
version=interface.version,
@@ -75,7 +75,8 @@ def __enter__(self):
7575
self._runtime.environ["DISPLAY"] = config.get_display()
7676

7777
self._runtime.startTime = dt.isoformat(dt.utcnow())
78-
self._resmon.start()
78+
if self._resmon:
79+
self._resmon.start()
7980
# TODO: Perhaps clean-up path and ensure it exists?
8081
os.chdir(self._runtime.cwd)
8182
return self._runtime
@@ -88,8 +89,9 @@ def __exit__(self, exc_type, exc_value, exc_tb):
8889
timediff.days * 86400 + timediff.seconds + timediff.microseconds / 1e6
8990
)
9091
# 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)
9395

9496
os.chdir(self._runtime.prevcwd)
9597

nipype/utils/profiler.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,6 @@
2424
_MB = 1024.0**2
2525

2626

27-
class ResourceMonitorMock:
28-
"""A mock class to use when the monitor is disabled."""
29-
30-
@property
31-
def fname(self):
32-
"""Get/set the internal filename"""
33-
return None
34-
35-
def __init__(self, pid, freq=5, fname=None, cwd=None):
36-
pass
37-
38-
def start(self):
39-
pass
40-
41-
def stop(self):
42-
return {}
43-
44-
4527
class ResourceMonitor(threading.Thread):
4628
"""
4729
A ``Thread`` to monitor a specific PID with a certain frequence

0 commit comments

Comments
 (0)