neuronsimulator / nrn

NEURON Simulator
http://nrn.readthedocs.io
Other
401 stars 117 forks source link

in dev version, nrniv -python registers PythonObject more than once following import, causing error #2406

Open ramcdougal opened 1 year ago

ramcdougal commented 1 year ago

Context

Overview of the issue

Running nrniv -python on the master branch calls class2oc("PythonObject", ...) more than once, thus raising an error.

% ~/bin/nrniv -python
NEURON -- VERSION 9.0.dev-1376-ge02907627 master (e02907627) 2023-06-23
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2022
See http://neuron.yale.edu/neuron/credits

>>> from neuron import h
/Users/ramcdougal/bin/nrniv: PythonObject already being used as a name
 near line 1
 from neuron import h
                     ^
libc++abi: terminating with uncaught exception of type neuron::oc::runtime_error: hoc_execerror: PythonObject already being used as a name
zsh: abort      ~/bin/nrniv -python

Expected result/behavior

No error should be generated from importing NEURON.

NEURON setup

Minimal working example - MWE

MWE that can be used for reproducing the issue and testing. A couple of examples:

% lldb ~/bin/nrniv
(lldb) target create "/Users/ramcdougal/bin/nrniv"
Current executable set to '/Users/ramcdougal/bin/nrniv' (arm64).
(lldb) r -python
Process 10115 launched: '/Users/ramcdougal/bin/nrniv' (arm64)
NEURON -- VERSION 9.0.dev-1376-ge02907627 master (e02907627) 2023-06-23
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2022
See http://neuron.yale.edu/neuron/credits

>>> from neuron import h
/Users/ramcdougal/bin/nrniv: PythonObject already being used as a name
 near line 1
 from neuron import h
                     ^
libc++abi: terminating with uncaught exception of type neuron::oc::runtime_error: hoc_execerror: PythonObject already being used as a name
Process 10115 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x000000019caca868 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`:
->  0x19caca868 <+8>:  b.lo   0x19caca888               ; <+40>
    0x19caca86c <+12>: pacibsp 
    0x19caca870 <+16>: stp    x29, x30, [sp, #-0x10]!
    0x19caca874 <+20>: mov    x29, sp
Target 0: (nrniv) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x000000019caca868 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x000000019cb01cec libsystem_pthread.dylib`pthread_kill + 288
    frame #2: 0x000000019ca3a2c8 libsystem_c.dylib`abort + 180
    frame #3: 0x000000019cabab18 libc++abi.dylib`abort_message + 132
    frame #4: 0x000000019caaa9f4 libc++abi.dylib`demangling_terminate_handler() + 312
    frame #5: 0x000000019c7af774 libobjc.A.dylib`_objc_terminate() + 160
    frame #6: 0x000000019cab9eb4 libc++abi.dylib`std::__terminate(void (*)()) + 20
    frame #7: 0x000000019cabcc2c libc++abi.dylib`__cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 36
    frame #8: 0x000000019cabcbd8 libc++abi.dylib`__cxa_throw + 140
    frame #9: 0x000000010086ee24 libnrniv.dylib`hoc_execerror_mes(s="PythonObject", t=<unavailable>, prnt=<unavailable>) at hoc.cpp:683:5 [opt]
    frame #10: 0x000000010086e72c libnrniv.dylib`hoc_execerror(s=<unavailable>, t=<unavailable>) at hoc.cpp:688:5 [opt]
    frame #11: 0x0000000100875934 libnrniv.dylib`class2oc(name="PythonObject", cons=(libnrnpython3.dylib`p_cons(Object*)), destruct=(libnrnpython3.dylib`p_destruct(void*)), m=0x000000010243db18, checkpoint=0x0000000000000000, mobjret=0x0000000000000000, strret=0x0000000000000000)(Object*), void (*)(void*), Member_func*, int (*)(void**), Member_ret_obj_func*, Member_ret_str_func*) at hoc_oop.cpp:1576:9 [opt]
    frame #12: 0x00000001024139c0 libnrnpython3.dylib`nrnpython_reg_real + 64
    frame #13: 0x0000000104da4b48 libnrniv.dylib`nrnpython_reg() + 1052
    frame #14: 0x0000000104d65d08 libnrniv.dylib`hoc_class_registration + 32
    frame #15: 0x0000000104e044d8 libnrniv.dylib`hoc_init + 1332
    frame #16: 0x0000000104e02934 libnrniv.dylib`hoc_main1_init(char const*, char const**) + 452
    frame #17: 0x0000000104cd0a44 libnrniv.dylib`Oc::Oc(ivSession*, char const*, char const**) + 424
    frame #18: 0x0000000104cd2f58 libnrniv.dylib`ivocmain_session(int, char const**, char const**, int) + 5304

(it continues)

ramcdougal commented 1 year ago

I did a pip3 install neuron-nightly in Linux on an x86_64 and did not run into this issue there.

nrnhines commented 1 year ago

Did not experience on M1 with

% cmake .. -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_INSTALL_PREFIX=install -DPYTHON_EXECUTABLE=`which python3`

or with

% cmake .. -DCMAKE_INSTALL_PREFIX=/Users/hines/nrn -DNRN_ENABLE_PYTHON_DYNAMIC=ON -DNRN_ENABLE_TESTS=ON