chute has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
Having a bit of an issue I'm hoping someone can help me with. I've created a script that uses Win32::GUI. The script retrieves webpages full of numbers and stuff, parses the numbers, compares them, etc. Processing can take minutes or more.
While the retrieving and processing is being done, the gui is sluggish and unresponsive. To solve this I discovered threads and implemented them, but it did not fix the problem. Everything looks correct to me, so I'm not sure what I can do to fix it. I'm using Strawberry 5.16.3, if that matters.
Here is a (heavily condensed) version of the code:
use strict; use Win32::GUI(); use WWW::Mechanize; use HTTP::Cookies; use threads; use Thread::Queue; #define some variables my @somearray = ("stuff"); my $thr; my $DataQueue = Thread::Queue->new(); #do all of the create windows/add control stuff my $main = Win32::GUI::Window->new( -name => "main", ); my $main_text_window = $main->AddTextfield( -name => "main_text", -multiline => 1, -readonly => 1, -vscroll => 1, ); $main->Show(); #call the main loop in a new thread $thr = threads->create(\&mainloop, @somearray); #wait for data, print data to GUI textbox while(Win32::GUI::DoEvents() != -1) { my $tmptxt = $DataQueue->dequeue(); $main_text_window->Append($tmptxt); } sub mainloop { while (1) { #lots of page getting and number crunching goes here $DataQueue->enqueue("some data"); } }
Also, I know about placing DoEvents() in the mainloop, but it slows down the processing quite a bit and does not help during page retrieval. I've also tried Win32::GUI::Timer (putting the dequeue and append command in the _Timer sub). It still seems to freeze when pages are being retrieved.
thanks!
|
---|