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:
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.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); }
In reply to Re: Responsive GUI without threads
by dk
in thread Responsive GUI without threads
by ruoso
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |