Page 1 of 1

pdb.set_trace() gives Segmentation Fault

Posted: Mon Mar 12, 2018 1:04 pm
by homerobse
I'm trying to debug a bigger project I have, and when I use pdb.set_trace function from the pdb (Python Debug) package of Python, I get a Segmentation Fault crash.

So, I decided to test with a very simple example code with an stimulus in a Hodgkin Huxley neuron:

Code: Select all

from neuron import h
import matplotlib.pyplot as plt

h.load_file("nrngui.hoc")  # load standard run system

soma = h.Section()
soma.insert('hh_original')

stim = h.IClamp(soma(0.5))

stim.delay = 1
stim.dur = 7
stim.amp = 20

rec_cell = h.Vector()
rec_cell.record(soma(0.5)._ref_v)

rec_stim = h.Vector()
rec_stim.record(stim._ref_i)

timeaxis = h.Vector()
timeaxis.record(h._ref_t)

print soma(0.5).v
h.tstop = 10

h.run()

print soma(0.5).v

plt.plot(timeaxis, rec_cell)
import pdb
pdb.set_trace()
plt.plot(timeaxis, rec_stim)
plt.show()
I get the following output:

Code: Select all

$ nrngui -python hh_example.py 
NEURON -- VERSION 7.5 master (4e5aee6) 2018-01-31
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2016
See http://neuron.yale.edu/neuron/credits

loading membrane mechanisms from /home/homerobse/lgn-v1/lgn_v1/snippets/x86_64/.libs/libnrnmech.so
Additional mechanisms from files
 hh_original.mod
-65.0
-73.3380680727
> /home/homerobse/lgn-v1/lgn_v1/snippets/hh_example.py(35)<module>()
-> plt.plot(timeaxis, rec_stim)
(Pdb) timeaxis/usr/local/bin/nrn/x86_64/bin/nrniv: Segmentation violation
 near line 0
 ^
Segmentation fault (core dumped)
Doesn't NEURON run well along with pdb? Or is it some problem with my installation?
If it is a problem with mine, any idea on how to fix it? I am running on Ubuntu 16.04 with gnome and installed NEURON without GUI.

Re: pdb.set_trace() gives Segmentation Fault

Posted: Mon Mar 12, 2018 6:04 pm
by ramcdougal
pdb works for me with your script if you run it with python hh_example.py instead of using nrngui. Make sure the neuron libraries are on your PYTHONPATH.

(There are subtle differences about how console input etc is handled when you launch with nrngui instead of python directly, that I suspect is responsible for the segfault. It's not your setup; we get the same thing.)