homepage Welcome to WebmasterWorld Guest from 54.237.213.31
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Server doesn't kill process
Using multi-threaded script
Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3323587 posted 10:15 am on Apr 27, 2007 (gmt 0)

I've written a basic API script, user enters data on a form, script goes off, looks stuff up, comes back with results.

As the info it was looking up was increasing, it was taking longer and longer, and I was getting annoyed with it.

So I converted it to use::threads;

Basically, the threads are simple, it spawns x threads simultaneously, to do the searching, and joins them immediately, hence waiting for them all to finish and reporting their results.

This works fine, the only problem is, the server sometimes doesn't kill the process anymore, and I eventually get a CGI timeout error.

Even if I put a die at the end of the script, the text "Died at ....." appears in the HTML, but the progress bar still doesn't stop, and the process doesn't disappear off my server.

If I reun the script from a command line, it runs and terminates instantly as it should.

Anyone else had a problem with multi-threaded CGI?

 

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 3323587 posted 10:27 am on Apr 27, 2007 (gmt 0)

just a wild guess here - try the detach() method on each thread.

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3323587 posted 11:55 am on Apr 27, 2007 (gmt 0)

Can't - I need to wait for them to finish so I can grab the output. According to spec, calling the join is blocking and will only return the output once the thread has terminated.

perl_diver

5+ Year Member



 
Msg#: 3323587 posted 4:07 pm on Apr 27, 2007 (gmt 0)

my experience with threads is very limited, have you tried using the kill() function?

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3323587 posted 5:08 pm on Apr 27, 2007 (gmt 0)

Hmmm, take a look at this website then:
[perl.com...]

Seems like you could learn something! Very handy and easy for parallel processing. Why run 12 API's at once, when you can run all 12 simultaneously, then the total time taken is only the time of the single longest one.

Anyway, as I said, you run a new thread, and if you don't detach it, you call $thread -> join; and it waits for the thread to terminate.

Drag_Racer

5+ Year Member



 
Msg#: 3323587 posted 7:09 am on Apr 28, 2007 (gmt 0)

maybe you could use LWP module's 'timeout' method to call your subroutines...

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3323587 posted 11:46 am on Apr 28, 2007 (gmt 0)

I'm just using LWP simple for this one.

LWP::UserAgent has a timeout method -- used to specify how long it tries for before it gives up. Not even nearly the same thing!

Anyway, I've just doubled it to 24 queries by adding another API, this one's using SOAP::Lite so that wouldn't cover it.

wruppert

10+ Year Member



 
Msg#: 3323587 posted 4:47 pm on May 1, 2007 (gmt 0)

The CPAN module POE was built to handle multi-threading. See [search.cpan.org...]

Dabrowski

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3323587 posted 5:26 pm on May 1, 2007 (gmt 0)

Looks interesting, but very complicated. I don't really understand it, could you post an example bit of code?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved