more useful options | |
PerlMonks |
Re: Do I need threading for my GUI?by shmem (Chancellor) |
on Feb 18, 2008 at 11:06 UTC ( [id://668511]=note: print w/replies, xml ) | Need Help?? |
A trick to avoid this is giving back control to the Tk main loop. This can either be
done by splitting up the "mainprocess" into singular tasks which call each other e.g. via Tk->after,
or storing that main-processes state somehow, thus making it re-entrant. You could also use the POE
framework to do either of those.
Term::ReadLine::Gnu uses another trick, it calls the Tk event handler DoOneEvent() directly - with due care, because it blocks if there's no event dispatched. If the above techniques (or just the use of POE) aren't feasible, you could use that trick. See Tk::Event. update: The proffered solution... Clock that goes backwards enhanced with a CPU-intensive, long running task. While the task is as silly as the clock itself, it is suitable for the POC. It's just a matter of adding a signal handler and calling the event dispatcher in a non-blocking way.
Pretty few lines of code added... well, I could shoehorn the alarm handler into one line, and it would be 3 lines - not counting the 'use Time::HiRes' line ;-) I guess it's not necessary to offer a code conversion job for something that simple. --shmem
In Section
Seekers of Perl Wisdom
|
|