Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tk, LWP, and blocking?
by saintmike (Vicar) on Mar 05, 2004 at 08:35 UTC | |
|
Re: Tk, LWP, and blocking?
by mawe (Hermit) on Mar 05, 2004 at 08:27 UTC | |
by Anonymous Monk on Mar 06, 2004 at 07:58 UTC | |
|
•Re: Tk, LWP, and blocking?
by merlyn (Sage) on Mar 05, 2004 at 15:56 UTC | |
|
Re: Tk, LWP, and blocking?
by zentara (Cardinal) on Mar 05, 2004 at 14:34 UTC | |
|
Re: Tk, LWP, and blocking?
by smackdab (Pilgrim) on Mar 05, 2004 at 23:36 UTC | |
|
Re: Tk, LWP, and blocking?
by Anonymous Monk on Mar 06, 2004 at 08:15 UTC |