Handling signals and performance issues.
donn at oz.net
Sun Dec 10 07:11:58 CET 2000
Quoth Roy Smith <roy at panix.com>:
| As for watching the end of a log file without burning CPU, as somebody
| else already mentioned, sleeping for a second between reads would be one
| good way. Another thing you might try is using a select() call to tell
| you when new data is readable on the file.
| You might want to look at the source to the unix "tail" command (you
| should be able to find it on any of the many GNU/Linux distribution
| sites) and see how it implements the "-f" option, which is essentially
| what you are trying to emulate.
The sleep sounds like a winner. I wouldn't expect too much from
select() in this application. select() wakes up when the indicated
I/O operation wouldn't block; for a read operation, because there's
either data or an end of file. At the end of a disk file, the second
condition obtains. (I wouldn't think select() is normally even
supported at all for disk files, but I'm too lazy to check.) The
bottom line is, there's no way to be notified by the system when
new data is appended to the end of a file, you just have to keep
Donn Cave, donn at oz.net
More information about the Python-list