Skip to content

Commit e25ac8c

Browse files
committed
Cleaned up some code and removed recursion from get_num_threads
1 parent a4e3ae6 commit e25ac8c

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

nipype/interfaces/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,15 +1211,17 @@ def _get_num_threads(proc):
12111211

12121212
# Import packages
12131213
import psutil
1214+
import logging as lg
12141215

12151216
# Init variables
12161217
num_threads = proc.num_threads()
12171218
try:
1219+
num_children = len(proc.children())
12181220
for child in proc.children():
1219-
num_threads = max(num_threads, child.num_threads(),
1220-
len(child.children()), _get_num_threads(child))
1221+
num_threads = max(num_threads, num_children,
1222+
child.num_threads(), len(child.children()))
12211223
except psutil.NoSuchProcess:
1222-
dummy = 1
1224+
pass
12231225

12241226
return num_threads
12251227

nipype/interfaces/utility.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,6 @@ def _run_interface(self, runtime):
449449
if isdefined(value):
450450
args[name] = value
451451

452-
# Record memory of function_handle
453-
#try:
454-
# import memory_profiler
455-
# proc = (function_handle, (), args)
456-
# mem_mb, out = memory_profiler.memory_usage(proc=proc, retval=True, include_children=True, max_usage=True)
457-
# setattr(runtime, 'cmd_memory', mem_mb[0]/1024.0)
458-
## If no memory_profiler package, run without recording memory
459-
#except:
460452
out = function_handle(**args)
461453

462454
if len(self._output_names) == 1:

nipype/pipeline/plugins/multiproc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ def run_node(node, updatehash, runtime_profile=False):
4444
mem_mb, retval = memory_profiler.memory_usage(proc=proc, retval=True,
4545
include_children=True,
4646
max_usage=True)
47-
runtime = (datetime.datetime.now() - start).total_seconds()
47+
run_secs = (datetime.datetime.now() - start).total_seconds()
4848
result['result'] = retval
4949
result['node_memory'] = mem_mb[0]/1024.0
50-
result['run_seconds'] = runtime
50+
result['run_seconds'] = run_secs
5151
result['cmd_memory'] = retval.runtime.get('cmd_memory')
5252
result['cmd_threads'] = retval.runtime.get('cmd_threads')
5353
except:
@@ -118,7 +118,7 @@ def __init__(self, plugin_args=None):
118118
self.plugin_args = plugin_args
119119
self.processors = cpu_count()
120120
memory = psutil.virtual_memory()
121-
self.memory = memory.total / (1024*1024*1024)
121+
self.memory = float(memory.total) / (1024.0**3)
122122
if self.plugin_args:
123123
if 'non_daemon' in self.plugin_args:
124124
non_daemon = plugin_args['non_daemon']

0 commit comments

Comments
 (0)