The following python code snippet creates a segmentation fault (making the ipython kernel crashes).
Code: Select all
from neuron import nrn, h
def section_print():
"""Print the different sections in the NEURON namespace"""
for sec in h.allsec():
print sec.name()
class Segfault(nrn.Section):
"""
Should wrap a NEURON section
"""
def __init__(self, name="fault"):
"""Initialize the section
"""
#Create a section within h
h("create {}".format("fault"))
#Address this section to the object
self = getattr(h, "fault")
#Set an attribut
self.L = 10
seg = Segfault()
section_print()
seg.L
The section_print shows that it works well at the beginning (there is a "fault" section created within h), but trying to get the attribut "L" makes the kernel crash. I found solutions (/dirty tricks) to avoid this problem but I do not understand why it is happening. I already came across segmentation faults, e.g. trying to change a cell model on the fly.
So I have three questions:
What is happening here?
How come neuron is capable of producing segmentation faults?
Are there simple rules of thumb to avoid segmentation fault using neuron?
Best,
Romain