in reply to stop counting (process)
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:
which is effectively a sleep 0.1, performed 10 times (with the update happening during each iteration of the loop).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 ++; } }
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:
and then test it in the subroutine:my $b_started = 0;
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 |