know if someone ping me
Chris Gonnerman
chris.gonnerman at newcenturycomputers.net
Fri Aug 24 00:07:30 EDT 2001
----- Original Message -----
From: "Alex Martelli" <aleax at aleax.it>
> You can do much better than this! With newer syslogd's, at
> least on Linux, you can log to a named pipe, so your Python
> program can just 'loop' reading from that named pipe and be
> woken up for processing when there's something to process --
> a MUCH better idea than 'polling' (continuosly read from
> a file) in terms of system-load for infrequent events.
Polling implemented with a loop like this:
while 1:
line = fp.readline()
if line == '':
time.sleep(1)
else:
# process line here
is actually fairly efficient on Unixoid OS's. You have up to a
one second delay before processing each line of the log, but
such a delay is normally not a problem.
I actually wrote a chat program in the old days using this
method (in C) and it ran fairly well AND left a log of the
communication automatically.
Blocking due to sleep() is just as good as blocking due to read()
on an empty pipe; polling with sleep() is just a *little bit* less
efficient than reading the pipe.
More information about the Python-list
mailing list