in reply to stop counting (process)

Hi fanticla,

While it's true that $mw->update() should provide a little relief from a frozen gui:

sub start_process{ my $count = 0; while ($count < 10) { $mw->update(); print $count; sleep 1; $count ++; } }

your code will still exhibit some sluggishness because of the sleep 1 statement, during which nothing can update.

You can fix that quite easily by using select in place of sleep, like this:

sub start_process{ my $count = 0; while ($count < 10) { print $count; # sleep 1; for (my $i = 0; $i < 10; $i++) { select(undef, undef, undef, 0.1); $mw->update; } $count ++; } }
which is effectively a sleep 0.1, performed 10 times (with the update happening during each iteration of the loop).

Of course, you can still press the button while the subroutine is being called.  If you'd like to only be able to call start_process if that subroutine is not currently in the process of running, you could add a boolean variable at the top of your code:

my $b_started = 0;
and then test it in the subroutine:
sub start_process{ $b_started++ and return; my $count = 0; while ($count < 10) { print $count; # sleep 1; for (my $i = 0; $i < 10; $i++) { select(undef, undef, undef, 0.1); $mw->update; } $count ++; } $b_started = 0; }

Replies are listed 'Best First'.
Re^2: stop counting (process)
by Anonymous Monk on Aug 25, 2010 at 06:50 UTC
    Or Time::HiRes (Time::HiRes::sleep(0.10);), if using Perl version 5.7.3 or greater.