pileofrogs has asked for the wisdom of the Perl Monks concerning the following question:

What's goin' down in groove-town, Monks?

How do you do something akin to a sig alarm in a multi-threaded perl app?

I have an existing perl app that does something similar to a web crawler. It's multi-threaded and uses LWP::UserAgent to pull web pages. Sometimes the connection times out, and I'd like to make that timeout shorter. The timeout value in LWP::UserAgent doesn't seem to do anything in at least one case. This could be because it's actually chasing redirects or something like that. I personally don't care enough to chase down infinite redirects (or whatever it actually is that's taking so long). If this weren't multi-threaded, I'd do sig alarm. But it is multi-threaded!

And now, even more than the practical answer to my problem, I'd like to know how you do a timeout/sig alarm like behaviour in multi-threaded perl?

Thanks!
--Pileofrogs

Replies are listed 'Best First'.
Re: Thread Killlin'
by woodpeaker (Novice) on Dec 10, 2008 at 21:11 UTC
    Well, I'm using forking and threads all time. So better way to full control is fork. You can start/stop any process in your system. BUT with threads I'm using simple Signals (if I'm using threads with loop). Sometimes I'm using just DESTROY function/method in my objects. But always just try to wait for threads ending.
Re: Thread Killlin'
by woodpeaker (Novice) on Dec 10, 2008 at 21:13 UTC
    Sorry, additional comment.
    Please read documentation for threads module. I remember they has force kill methods for threads