due to threading issues. The problem is that the matplotlib gui thread seems
to prevent response from the hoc interpreter. Previously, the code sequence
below was effective in dealing with this issue (similar to ipython in that there's
a separate loop for graphics). Right now, when running with python 2.7.3
and NEURON 7.4 (978:41e073aceb37) 2013-10-30, the interpreter hangs. If any
python gurus have suggestions on how to fix this problem, please let me know.
Thanks
Run sequence:
nrniv
nrnpython("execfile('nrnivthread.py')") // see nrnivthread.py code below
nrnpython("plot([5,1,3])")
Note that this warning comes up :
QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread
Code: Select all
# load with execfile()
# from neuron import h # h should be present in the global namespace
import time
from threading import *
from pylab import *
from matplotlib._pylab_helpers import Gcf
hasgtk=True
try:
import gtk
except:
hasgtk=False
# Thread class that executes processing
class NRNThread(Thread):
"""NRNThread Class."""
def __init__(self,sleepdt=0.1):
"""Init NRNThread Class."""
Thread.__init__(self)
self._want_abort = 0
self.sleepdt = sleepdt
def run(self):
from neuron import h
"""Run NRNThread."""
# code executing in the new thread
while True:
if self._want_abort:
return "DONE"
h.doNotify() # specific for handling hoc graphics
if hasgtk:
# messing with code from : (/usr/lib/pymodules/python2.6/matplotlib/backends/backend_gtk.py:66)
for manager in Gcf.get_all_fig_managers():
manager.window.show()
figManager = Gcf.get_active()
if figManager is not None:
figManager.canvas.draw()
figManager.canvas.flush_events()
time.sleep(self.sleepdt)
# Here's where the result would be returned
def abort(self):
"""abort NRNThread."""
# Method for use by main thread to signal an abort
self._want_abort = 1
bg = NRNThread() # these 2 lines properly belong in the calling routines
bg.start() # start is part of base class Thread