iplot: long datablock stucks
Closed this issue · 3 comments
Passing a long datablock (~4000 lines) stucks
import gplot
iplot = gplot.Iplot(tmp='$')
iplot([1.000313517867877869656356345634865]*4000, ' w l')
while 3000 lines would be processed.
With uri=False
it works and the plot shows up
iplot = gplot.Iplot(tmp='$', uri=False)
iplot([1.000313517867877869656356345634865]*4000, ' w l')
So could be made to the default value.
Here is the problem extracted and can be tested also in normal python shell:
import subprocess
import os
gp = subprocess.Popen('gnuplot ', shell=True, stdin=subprocess.PIPE,
universal_newlines=True, bufsize=0)
os.system('rm -f tmp.png')
os.mkfifo('tmp.png')
print('''
set out "tmp.png"
$data1 <<EOD
''', file=gp.stdin)
print("\n".join(map(str,[1.000313517867877869656356345634865]*4000)), file=gp.stdin)
Again, this will stuck for 4000 lines (but run for 3000 lines).
The problem arises when gnuplot opens the created fifo with set out "tmp.png"
. If tmp.png
does not exists, a normal file is created and it runs.
According to
https://askubuntu.com/questions/439289/cat-to-named-pipe-causes-hang
http://kodedevil.com/2017/07/07/linux-fifos-python/
something is needed to read the fifo.
Indeed, inserting fifo = os.open('tmp.png', os.O_RDONLY)
right after set output
, the following works:
import subprocess
import os
gp = subprocess.Popen('gnuplot ', shell=True, stdin=subprocess.PIPE,
universal_newlines=True, bufsize=0)
os.system('rm -f tmp.png')
os.mkfifo('tmp.png')
print('set out "tmp.png"', file=gp.stdin)
fifo = os.open('tmp.png', os.O_RDONLY)
print('$data1 <<EOD', file=gp.stdin)
print("\n".join(map(str,[1.000313517867877869656356345634865]*4000)), file=gp.stdin)