尝试通过管道进行实时绘图的测试实验。
gp = os.popen("gnuplot -persist", 'w')
data = [(x,x*x) for x in range(10)]
print data
print >> gp, "set grid"
print >> gp, "show grid"
data = []
os.remove('data.txt')
f = open('data.txt', 'a')
f.write("0.000000 0.000000\n")
f.write("1.000000 1.000000\n")
f.close()
print >> gp, "plot 'data.txt' volatile with lines"
gp.flush()
#time.sleep(2)
for x in range(2,10):
f = open('data.txt', 'a')
f.write("%f %f\n"%(x,x*x))
f.close()
gp.flush()
#time.sleep(1) # deadlock here
gp.flush()
这是有效的,直到我在循环中取消注释time.sleep(1)。在所有睡眠之间添加了gp.flush()但没有结果。我怎么能睡觉处理popens?