Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not even looking at your source code, there are two ways you could easily do this more efficiently and handle multiple files.</p> <ol> <li><p>Don't bother running tail unless you have to. Simply <code>os.stat</code> all of the files and record the last modified time. If the last modified time is different, then raise a notification. </p></li> <li><p>Use <a href="https://github.com/seb-m/pyinotify" rel="noreferrer">pyinotify</a> to call out to Linux's <a href="http://en.wikipedia.org/wiki/Inotify" rel="noreferrer">inotify</a> facility; this will have the kernel do option 1 for you and call back to you when any files in your directory change. Then translate the callback into your osd notification.</p></li> </ol> <p>Now, there might be some trickiness depending on how many notifications you want when there are multiple messages and whether you care about missing a notification for a message.</p> <p>An approach that preserves the use of <code>tail</code> would be to instead use <code>tail -f</code>. Open all of the files with <code>tail -f</code> and then use the <code>select</code> module to have the OS tell you when there's additional input on one of the file descriptors open for <code>tail -f</code>. Your main loop would call select and then iterate over each of the readable descriptors to generate notifications. (You could probably do this without using <code>tail</code> and just calling <code>readline()</code> when it's readable.)</p> <p>Other areas of improvement in your script:</p> <ul> <li>Use <code>os.listdir</code> and native Python filtering (say, using list comprehensions) instead of a <code>popen</code> with a bunch of <code>grep</code> filters.</li> <li>Update the list of buffers to scan periodically instead of only doing it at program boot.</li> <li>Use <code>subprocess.popen</code> instead of <code>os.popen</code>.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload