h.fadvance() stops python threading, why?
Posted: Tue May 09, 2017 4:35 pm
Hi all,
I have a bit strange problem with using threading Python module with NEURON.
I run NEURON -- Release 7.4 (1370:16a7055d4a86) 2015-11-09 from Python 2.7.12 (default, Nov 19 2016, 06:48:10) script under Linux 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux.
Sorry, probably too much details in previous post.
Here very simple code to show the problem.
Result looks like this
I have a bit strange problem with using threading Python module with NEURON.
I run NEURON -- Release 7.4 (1370:16a7055d4a86) 2015-11-09 from Python 2.7.12 (default, Nov 19 2016, 06:48:10) script under Linux 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux.
Sorry, probably too much details in previous post.
Here very simple code to show the problem.
Code: Select all
import threading, time, sys
from datetime import datetime
from neuron import h
buf = []
def VerySlowProcess():
global buf
while len(buf) > 0:
#Print time and a firs element of the buffer
now = datetime.now()
sys.stderr.write( "Time:{}.{}.{} BUFx:{}\n".format(now.hour, now.minute, now.second, buf[0]) )
#Delete is!
del buf[0]
time.sleep(1)
#Fill the buffer
buf += range(100)
#Create a thread
dthread = threading.Thread(target=VerySlowProcess)
#Start it
dthread.start()
#now let's wait a bit to see that tread works well
sys.stderr.write( "Time to sleep\n" )
time.sleep(5)
sys.stderr.write( "Ready to go\n" )
#creates a 100 cables to keep neuron busy
c = [ h.Section() for x in xrange(100) ]
for n in c:
n.nseg = 20
n.L = 700
n.insert("hh")
#Now run a simulation and watch the treading
h.finitialize()
h.fcurrent()
h.frecord_init()
sys.stderr.write( "Run a simulation\n" )
while h.t < 500. : h.fadvance()
sys.stderr.write( "Finished\n" )
Code: Select all
NEURON -- Release 7.4 (1370:16a7055d4a86) 2015-11-09
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2015
See http://www.neuron.yale.edu/neuron/credits
Time to sleep
Time:9.46.59 BUFx:0
Time:9.47.0 BUFx:1
Time:9.47.1 BUFx:2
Time:9.47.2 BUFx:3
Time:9.47.3 BUFx:4
Time:9.47.4 BUFx:5
Ready to go
Run a simulation
Finished
Time:9.47.21 BUFx:6
Time:9.47.22 BUFx:7
Time:9.47.23 BUFx:8
Time:9.47.24 BUFx:9
Time:9.47.25 BUFx:10
Time:9.47.26 BUFx:11
Time:9.47.27 BUFx:12
Time:9.47.28 BUFx:13