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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.