[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problem with gnuplot backend + popen2 + non-blocking mode
From: |
John W. Eaton |
Subject: |
Problem with gnuplot backend + popen2 + non-blocking mode |
Date: |
Thu, 24 Apr 2008 13:29:06 -0400 |
On 24-Apr-2008, Michael Goffioul wrote:
| while testing some code, I noticed some problems in the
| gnuplot backend when octave sends a lot of data to gnuplot
| through the pipe (typically when drawing surfaces). It looks
| like "unfinished" data transfer with only partial drawing.
| [Note: tested under Windows/MSVC]
|
| I noticed that the gnuplot backend no uses popen2, which
| opens the communication pipes in non-blocking mode
| by default. I think that at some point when the pipe buffer
| gets full, some writing function calls silently fail (because
| of the non-blocking mode) and the associated data gets
| lost.
|
| I did a test by manually starting gnuplot with popen2 in
| blocking mode and called __go_draw_figure__ on the
| stream, I didn't have the problem anymore.
|
| Would it be a problem to use popen2 in blocking mode?
I would have expected the pipe that is open for writing to already be
in blocking-write mode. Here is what I see:
octave:1> [to_gnuplot, from_gnuplot] = popen2 ("gnuplot")
in = 4
out = 5
octave:2> bitand (fcntl (to_gnuplot, F_GETFL, 0), O_NONBLOCK)
ans = 0
octave:3> bitand (fcntl (from_gnuplot, F_GETFL, 0), O_NONBLOCK)
ans = 2048
Do you also see a non-zero result for the "to_gp" stream? If so, then
does the following patch fix the problem?
Instead of fixing the problem in gnuplot_drawnow, maybe the
octave_popen2 function for Windows should be fixed to open the writing
stream in blocking mode, same as the Unixy popen2 does?
jwe
diff --git a/scripts/plot/gnuplot_drawnow.m b/scripts/plot/gnuplot_drawnow.m
--- a/scripts/plot/gnuplot_drawnow.m
+++ b/scripts/plot/gnuplot_drawnow.m
@@ -78,6 +78,12 @@ function [plot_stream, enhanced] = open_
[plot_stream(1), plot_stream(2), pid] = popen2 (cmd);
if (pid < 0)
error ("drawnow: failed to open connection to gnuplot");
+ else
+ ## Ensure that the stream open for writing to gnuplot is in
+ ## blocking-write mode:
+ oflags = fcntl (plot_stream(1), F_GETFL, 0);
+ nflags = bitand (oflags, bitcmp (O_NONBLOCK));
+ fcntl (plot_stream(1), F_SETFL, nflags);
endif
else
plot_stream = popen (cmd, "w");