From: Michael H. <hag...@jp...> - 2002-08-28 09:00:54
|
Dear Jonathan, Jonathan Ricketson writes: > Hey Michael, the interface that you have written for gnuplot is > really good. But I am having a problem with using it from a web > browser. > > The funny thing is that it works fine from the command line but when > I try to run the script from a browser it has this problem: > > gnuplot> set title "Some Title" > gnuplot> set term png > gnuplot> set output "/var/www/sample.png" > gnuplot> set data style linespoints > gnuplot> plot '/tmp/@18326.0' notitle > > gnuplot> plot '/tmp/@18326.0' notitle > ^ > can't read data file "/tmp/@18326.0" > line 0: (No such file or directory) > > the problem seems to be that the tmp file is deleted too quickly, or > doesn't exist yet... Because from the command line I can replicate > the problem by the following code: > > g.plot(data) > raw_input('Please press return to continue...\n') > > If I keep the raw input line, then it works, otherwise if I take it > out, then it has the same error as above. > > If you have any idea what the problem might be I would really > appreciate your help. > > Jonathan Your diagnosis is exactly correct. Communication with gnuplot is via temporary files by default, and the temporary files are deleted as soon as the "Gnuplot.Data" object is garbage collected, which in your example probably occurs when the script ends or when you plot something else. (Until you plot something else, the Gnuplot object keeps a reference to all of the old plot items to prevent they're being garbage collected.) There is no way for Gnuplot.py to know when gnuplot is done reading the temporary file, so there is no general way for it to know when it is actually safe to delete the file. Possible solutions are: 1. Use "inline data" instead of temporary files to communicate with gnuplot. This is already available in gnuplot for many plotting modes if you specify the "inline=1" option to the constructor of the Data object, or if you set GnuplotOpts.prefer_inline_data=1. 2. Introduce a delay between the time you plot and the time you allow the Data object to be deleted. You could just use time.sleep(), or in your example you might watch for the creation of the /var/www/sample.png file and at that point assume that gnuplot is done with the temporary file. 3. Improve Gnuplot.py for all of us by adding an option to use named pipes instead of temporary files. I think it should be possible for Gnuplot.py to know when gnuplot has finished reading the data from the named pipe so that there is no more ambiguity. Note that it will take some effort to make such a solution portable across operating systems, which is the main reason that I haven't undertaken it already. I have directed this reply to the gnuplot-py-users mailing list. Please join this list if you are interested in Gnuplot.py issues. You can do so at the following web site: http://lists.sourceforge.net/lists/listinfo/gnuplot-py-users Yours, Michael -- Michael Haggerty hag...@jp... |