|
From: John M. <mcf...@gm...> - 2013-08-06 20:08:36
|
I am trying to write some code that uses an input thread to check for user
input while another thread is running some calculations (see example below).
What I have noticed is that just including an import of pyplot (regardless
of whether it is used by the code or not) causes the call to raw_input in
the input thread to block the main thread. It works fine when I don't
import pyplot. Importing pyplot is a consequence of other libraries that I
need to use in the code, so I would like to find a way to make this work.
I have python 2.7.3, matplotlib 1.2.0, and am currently using the GTKAgg
backend. Any help is much appreciated.
Here is the example code:
import time
import threading
import matplotlib.pyplot # Works fine if this is commented out
def input_thread():
raw_input('Press a key:')
print "Input data received"
thread = threading.Thread(target=input_thread)
thread.start()
time.sleep(.01)
print
# Main thread (e.g. a calculation that can take some time)
for i in xrange(10):
print i
time.sleep(.5)
--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Importing-pyplot-blocks-input-thread-tp41731.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
|