nonblocking read of one xml element?

mh at mh at
Wed Feb 6 00:32:01 CET 2008

Stefan Behnel <stefan_ml at> wrote:
> mh at wrote:
> > I'm parsing a log file that's being written out in
> > real time.
> > This is part of an event loop, so I want to have some code
> > that looks like this:
> >
> >    when logfile is readable:
> >        read one <entry> node, including children
> >        but don't try to read past </entry>, so that
> >        the read won't block.
> Do you have any control over the program that writes the log file? Maybe you
> could make it write the log to a pipe or socket instead, which you could then
> connect an XML parser to from the Python side (maybe from a thread to avoid
> blocking I/O).

Unfortunately, no... it's the oracle database, which can write
its auditing logs to external xml files.

This is great because we can tail those files in real time and
follow what is going on.

Basically, they have one audit xml file per session, and they
write the filename to a control file every time they create
a new audit file.

So, the logic is something like this:

    whenever the control file is readable:
        # a new audit file has been created
        read audit filename, open, read
        xml header up to first audit record,
        and set up readable callback

    whenever an audit logfile is readable:
        read the next <auditlog>
        # but don't block

Or perhaps there's some nonblocking file I/O I can do?


Mark Harrison
Pixar Animation Studios

More information about the Python-list mailing list