But one task still seems to me like one where "threads" is indeed the answer, which is making a responsive Graphical User Interface.

Doubtful at least. Why GUI programs are different from any other programs? It is quite possible to display a progress of a long process by forking it off and reading its output, the only difference that the reading pipe should be non-blocking. I don't know what class you should use for Gtk, but the idea is roughly like this:

use IO::Handle; use Fcntl; use POSIX qw(exit); $SIG{PIPE} = 'IGNORE'; my $handle = IO::Handle-> new; $handle-> autoflush(1); my $pid = open( $handle, '-|'); if ( $pid) { # parent # make it non-blocking my $fl = fcntl( $handle, F_GETFL, 0); die "$!" unless defined $fl; fcntl( $handle, F_SETFL, $fl|O_NONBLOCK) or die "$!"; # attach to your gui system so your callbacks are # pinged whenever something appears on $handle MyFictitiousGUI::FileListener->attach( $handle, on_read => sub { message( <$handle>); }, on_close => sub { message("it's over!") } ); } else { # child $|++; while ( do_computation) { print "$percents done\n"; } POSIX::_exit(0); }
Most probably POE can do this as well, but it must know about you GUI toolkit event loop structure. If you're doing it by yourself though, you should also eventually call waitpid($pid,WNOHANG) so the child process won't become a zombie.

In reply to Re: Responsive GUI without threads by dk
in thread Responsive GUI without threads by ruoso

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.