Hi.
I'm trying to write a web client that uses LWP and Tk. Unfortunately, calls to get() keep blocking and freezing-up the program for often-significant amounts of time while LWP sends the request and receives response. Is there some way to get around this besides using Thread.pm or threads.pm? I tried update(), but that didn't seem to work. What I really need is way to call get() (or request()) and get access to the response object without the windows freezing and becoming unresponse for a while. Here's some example code:
#!/usr/bin/perl -w use strict; use Tk; use Tk::Pane; use LWP; use vars qw($URL); use vars qw($DOC_VIEWER); use vars qw($DOC); my $lwp = new LWP::UserAgent; my $browser = new MainWindow; my $url_entry_frame = $browser->Frame->pack(-side => 'top', -padx => 3 +, -pady => 4); $url_entry_frame->Entry( -textvariable => \$URL, -width => 100 )->pack(-side => 'left', -padx => 1); $url_entry_frame->Button( -text => 'GO', -command => sub { sendRequest() } )->pack(-side => 'left', -padx => 1); $DOC_VIEWER = $browser->Scrolled('Pane', Name => 'doc_viewer', -scrollbars => 'se', -sticky => 'we', -gridded => 'y' )->pack(-expand => 1, -fill => 'both'); my $status = $browser->Label->pack(-side => 'bottom'); MainLoop; sub sendRequest { $DOC->destroy if ($DOC); $status->update; $status->configure(-text => 'Requesting...'); my $response = $lwp->get($URL); $status->configure(-text => 'Done.'); if ($response->is_success) { $DOC = $DOC_VIEWER->Label(-text => $response->content)->pack; } else { die $response->error_as_HTML; } }
In reply to Tk, LWP, and blocking? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |