Skip to content

Instantly share code, notes, and snippets.

@oesteban
Created November 21, 2017 23:46
Show Gist options
  • Save oesteban/21be178b1e9ab6231ece2cd1e03de7f3 to your computer and use it in GitHub Desktop.
Save oesteban/21be178b1e9ab6231ece2cd1e03de7f3 to your computer and use it in GitHub Desktop.
Crashing nipype with memory consumption
Top 1 lines
#1: traits/has_traits.py:3008: 1.3 KiB
if not meta_eval( getattr( trait, meta_name ) ):37 other: 14.1 KiB
Total allocated size: 15.3 KiB
Top 1 lines
#1: testnipype.py:50: 8388608.0 KiB
large_str = ' ' * (8 * 1024**3)94 other: 362.5 KiB
Total allocated size: 8388970.6 KiB
Top 1 lines
#1: testnipype.py:50: 8388608.0 KiB
large_str = ' ' * (8 * 1024**3)110 other: 383.4 KiB
Total allocated size: 8388991.4 KiB
Top 1 lines
#1: testnipype.py:50: 8388608.0 KiB
large_str = ' ' * (8 * 1024**3)132 other: 17046.6 KiB
Total allocated size: 8405654.6 KiB
171121-15:37:05,797 workflow INFO:
Workflow work settings: ['check', 'execution', 'logging', 'monitoring']
171121-15:40:46,671 workflow INFO:
Running serially.
171121-15:40:46,685 workflow INFO:
[Node] Setting-up "work.node09999" in "/tmp/tmp4qftuz_6/work/node09999".
171121-15:40:46,687 workflow INFO:
[Node] Running "node09999" ("nipype.interfaces.base.CommandLine"), a CommandLine Interface with command:
ls -lah.
171121-15:40:46,693 interface WARNING:
Could not get linked libraries for "ls".
171121-15:40:46,698 workflow WARNING:
[Node] Exception "work.node09999" (/tmp/tmp4qftuz_6/work/node09999)
171121-15:40:46,698 workflow ERROR:
Node node09999 failed to run on host dendrite.
171121-15:40:46,699 workflow ERROR:
Saving crash info to /home/oesteban/tmp/test/crash-20171121-154046-oesteban-node09999-eafd76be-694b-4b85-8dbd-eee2fda53494.pklz
Traceback (most recent call last):
File "/home/oesteban/workspace/nipype/nipype/pipeline/plugins/linear.py", line 43, in run
node.run(updatehash=updatehash)
File "/home/oesteban/workspace/nipype/nipype/pipeline/engine/nodes.py", line 405, in run
self._run_interface(execute=True)
File "/home/oesteban/workspace/nipype/nipype/pipeline/engine/nodes.py", line 508, in _run_interface
self._result = self._run_command(execute)
File "/home/oesteban/workspace/nipype/nipype/pipeline/engine/nodes.py", line 640, in _run_command
result = self._interface.run()
File "/home/oesteban/workspace/nipype/nipype/interfaces/base.py", line 1089, in run
runtime = self._run_interface(runtime)
File "/home/oesteban/workspace/nipype/nipype/interfaces/base.py", line 1664, in _run_interface
runtime = run_command(runtime, output=self.terminal_output)
File "/home/oesteban/workspace/nipype/nipype/interfaces/base.py", line 1392, in run_command
close_fds=True)
File "/home/oesteban/.anaconda3/lib/python3.6/subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "/home/oesteban/.anaconda3/lib/python3.6/subprocess.py", line 1260, in _execute_child
restore_signals, start_new_session, preexec_fn)
OSError: [Errno 12] Cannot allocate memory
import os
import linecache
from nipype.interfaces import base as nib, utility as niu
from nipype.pipeline import engine as pe
from nipype.pipeline import plugins as pp
from time import sleep
import tracemalloc
tracemalloc.start()
def display_top(group_by='lineno', limit=1):
snapshot = tracemalloc.take_snapshot()
snapshot = snapshot.filter_traces((
tracemalloc.Filter(False, "<frozen importlib._bootstrap>"),
tracemalloc.Filter(False, "<unknown>"),
))
top_stats = snapshot.statistics(group_by)
msg = "Top %s lines\n" % limit
for index, stat in enumerate(top_stats[:limit], 1):
frame = stat.traceback[0]
# replace "/path/to/module/file.py" with "module/file.py"
filename = os.sep.join(frame.filename.split(os.sep)[-2:])
msg += ("#%s: %s:%s: %.1f KiB\n"
% (index, filename, frame.lineno, stat.size / 1024))
line = linecache.getline(frame.filename, frame.lineno).strip()
if line:
msg += ' %s' % line
other = top_stats[limit:]
if other:
size = sum(stat.size for stat in other)
msg += "%s other: %.1f KiB\n" % (len(other), size / 1024)
total = sum(stat.size for stat in top_stats)
msg += "Total allocated size: %.1f KiB\n" % (total / 1024)
return msg
# import hunter
# hunter.trace(threading_support=True)
# plugin = pp.multiproc.MultiProcPlugin()
iface = nib.CommandLine(command='ls -lah')
# iface.run()
# n1 = pe.Node(iface, name='sleep')
print(display_top())
large_str = ' ' * (8 * 1024**3)
print(display_top())
wf = pe.Workflow(name='work')
print(display_top())
wf.add_nodes([pe.Node(iface, name='node%05d' % i) for i in range(10000)])
print(display_top())
# res = wf.run(plugin='MultiProc', plugin_args={'maxtasksperchild': None})
res = wf.run()
print(display_top())
large_str += ' ' # So that the garbage collector does not clean it
print(large_str[:10], large_str[-10:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment