[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: nonblocking read of one xml element?

Stefan Behnel

2/5/2008 7:45:00 PM

mh@pixar.com 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).

Stefan
1 Answer

Mark Harrison

2/5/2008 11:32:00 PM

0

Stefan Behnel <stefan_ml@behnel.de> wrote:
> mh@pixar.com 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?

Thanks,
Mark

--
Mark Harrison
Pixar Animation Studios