From: Ken S. <k.w...@qu...> - 2011-08-18 15:31:15
|
Folks Apologies in advance if there's an FAQ, but I can't find it... (Feel free to point it out to me...) There also doesn't seem to be a simple way to search the Sourceforge archives for this group... I've been using Gnuplot.py for a while now, and I keep running into the same problem. I'm creating postscript plots, but at the end of my script I'd like to convert them into JPEGs using ImageMagick (convert). The problem is that (presumably because of threading) Gnuplot.py is sometimes not completing its work before I attempt to convert the plot. Hence ImageMagic complains about missing postscript files - or the postscript files are incomplete when conversion starts. Is there a way to turn threading/FIFOs OFF? Or is there a way I can use "join" to force my python program to WAIT for the plot to be completed before attempting to convert it? I've tried setting the following after my Gnuplot import: Gnuplot.GnuplotOpts.prefer_fifo_data = 0 Gnuplot.GnuplotOpts.support_fifo = 0 Gnuplot.GnuplotOpts.prefer_inline_data = 1 but to no avail. The only thing I'm doing at the moment is checking that the postscript file exists - but this is just a fudge and doesn't prevent other issues if the file is incomplete. Below are example errors... Ken Example errors: MISSING ps file convert: unable to open image `/tmp/tempPSPlots/ 1095652401023547700_lc.ps': @ error/blob.c/OpenBlob/2584. convert: missing an image filename `/psdb/images/ps1ss/lightcurves/1095652401023547700_lc.jpeg' @ error/convert.c/ConvertImageCommand/2949. INCOMPLETE ps file (presumably that's what causes ghostscript to barf) Error: /syntaxerror in -file- Operand stack: MLshow Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- %--nostringval-- 2 %stopped_push --nostringval-- -- nostringval-- %--nostringval-- false 1 %stopped_push 1894 1 3 %oparray_pop %1893 1 3 %oparray_pop 1877 1 3 %oparray_pop 1771 1 3 %%oparray_pop --nostringval-- %errorexec_pop .runexec2 %--nostringval-- --nostringval-- --nostringval-- 2 %stopped_push Dictionary stack: --dict:1158/1684(ro)(G)-- --dict:0/20(G)-- --dict:80/200(L)-- --dict:176/256(L)-- Current allocation mode is local Last OS error: 2 GPL Ghostscript 9.00: Unrecoverable error, exit code 1 |
From: Michael H. <mh...@al...> - 2011-08-22 08:46:19
|
On 08/18/2011 05:31 PM, Ken Smith wrote: > Apologies in advance if there's an FAQ, but I can't find it... (Feel > free to point it out to me...) There is a FAQ.txt in the Gnuplot.py distribution. The first FAQ question is closely related to your problem. > The problem is that (presumably because of threading) Gnuplot.py is > sometimes not completing its work before I attempt to convert the > plot. Hence ImageMagic complains about missing postscript files - or > the postscript files are incomplete when conversion starts. > > Is there a way to turn threading/FIFOs OFF? Or is there a way I can > use "join" to force my python program to WAIT for the plot to be > completed before attempting to convert it? The problem is not so much the multithreading in Gnuplot.py (which anyway should be turned off if your turn off the use of FIFOs) but rather the fact that a separate process (the gnuplot program) is doing the real work. I believe that if you close() the Gnuplot object explicitly then it will wait for gnuplot to finish (though of course you will have to create a new Gnuplot object if you want to do more work afterwards): g = Gnuplot.Gnuplot() # Use g to plot what you want g.close() # At this point I think that all of the gnuplot output should be # done. Please try this out and tell us if it works. Michael -- Michael Haggerty mh...@al... http://softwareswirl.blogspot.com/ |
From: Ken S. <k.w...@qu...> - 2011-08-23 11:30:23
|
Many thanks Michael Indeed I just needed to close my Gnuplot() objects. Not a single error (in ~10,000 plots) after I did that. Cheers, Ken On 22 Aug 2011, at 09:22, Michael Haggerty wrote: > On 08/18/2011 05:31 PM, Ken Smith wrote: >> Apologies in advance if there's an FAQ, but I can't find it... (Feel >> free to point it out to me...) > > There is a FAQ.txt in the Gnuplot.py distribution. The first FAQ > question is closely related to your problem. > >> The problem is that (presumably because of threading) Gnuplot.py is >> sometimes not completing its work before I attempt to convert the >> plot. Hence ImageMagic complains about missing postscript files - or >> the postscript files are incomplete when conversion starts. >> >> Is there a way to turn threading/FIFOs OFF? Or is there a way I can >> use "join" to force my python program to WAIT for the plot to be >> completed before attempting to convert it? > > The problem is not so much the multithreading in Gnuplot.py (which > anyway should be turned off if your turn off the use of FIFOs) but > rather the fact that a separate process (the gnuplot program) is doing > the real work. I believe that if you close() the Gnuplot object > explicitly then it will wait for gnuplot to finish (though of course > you > will have to create a new Gnuplot object if you want to do more work > afterwards): > > g = Gnuplot.Gnuplot() > # Use g to plot what you want > g.close() > # At this point I think that all of the gnuplot output should be > # done. > > Please try this out and tell us if it works. > > Michael > > -- > Michael Haggerty > mh...@al... > http://softwareswirl.blogspot.com/ |