A few more details about the problem I've been having with
a bad interaction between popen and various other calls. To
recap briefly:
def get_next_line
@file = popen("zcat next_file") if file not open..
OR
@file = Zlib::GzipReader.new(next_file)
line = @file.readline
(check to see if line returned, go back and open new
file if we reached the end of file
end
def do_some_work
res = do a mysql query
while (line = get_next_line)
** something = res.fetch_row
.. do some work
end
end
The basic problem is that the res.fetch_row sometimes
returns nil when it shouldn't. But the same problem was
happening with some other things, like file write operations.
The problem always coincides with the end of one
file and opening a new one, though I don't know
if it happens before or after I open the new one.
If I have my MySQL dbh set to dbh.query_with_result = true
I don't experience the problem in the case mentioned above -
because all of the IO is handled before I start doing the
opens.
The problem is hard to replicate. Test runs with small datafiles
don't generate the problem, and adding error trapping around more
operations sometimes, but not always, makes the problem shift around.
The mysql death is more consistent than the writing to an ouput
file death.. This is under ruby 1.8.1 (2004-05-02) [i386-freebsd5].
The problem occurs under FreeBSD 4.10 and 5.2.1.
I'm not sure where the problem would be, since it seems to
occur both when I popen a zcat or when I use GzipReader.
But it _seems_ like the symptom is that a file descriptor
is getting trashed or closed when it shouldn't be...
are there known ways to accidentally close file descriptors
that I might be stepping on?
(is it correct to call
begin
file.readline
end
if (we got to the end of the file)
file.close
end
?)
Any further clues on this would appreciated again. :)
-Dave
--
work: dga / lcs.mit.edu me: dga / pobox.com
MIT Laboratory for Computer Science http://www.angio.net/