Here's a simple threaded tail and a simple Tk app that uses it.

The threaded tail doesn't chase inodes or anything fancy like that. It only displays new lines not a few existing ones (though that could be easily changed).

It uses negligable cpu with the default setting of 100 milliseconds sleep after a failed attempt to read a new line.

#!perl -slw use strict; package threads::Tail; use threads; use threads::shared; use Thread::Queue; our @ISA = 'Thread::Queue'; my $die:shared = 0; sub tail{ my( $Q, $filename, $delay ) = @_; open my $fh, '<', $filename or die "$filename: $!"; seek $fh, 0, 2; until( $die ) { my $line = <$fh>; Win32::Sleep( $delay ), next unless defined $line; $Q->enqueue( $line ); } } sub new { my( $class, $filename, %args ) = @_; my $Q = new Thread::Queue; threads->new( \&tail, $Q, $filename, $args{ delay } || 100 )->deta +ch; return bless $Q, $class; } sub DESTROY { $die = 1; sleep 1; return; } 1; package main; #use threads::Tail; my $Q = threads::Tail->new( $ARGV[ 0 ], delay => 100 ); require Tk::Text; my $mw = MainWindow->new( -width => 400, -height => 400 ); my $text = $mw->Text( -wrap => 'none', -height => 20, )->pack( -expand => 1 ); my $repeat; $repeat = $mw->repeat( 100 => sub { while( $Q->pending ) { my $line = $Q->dequeue; return unless $line; $text->insert( 'end', $line ); $text->yview( 'end' ); } } ); $mw->MainLoop;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Tk GUI and Listen? by BrowserUk
in thread Tk GUI and Listen? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.