Welcome to WebmasterWorld Guest from 54.167.58.159

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Server doesn't kill process

Using multi-threaded script

     

Dabrowski

10:15 am on Apr 27, 2007 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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

10:27 am on Apr 27, 2007 (gmt 0)

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



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

Dabrowski

11:55 am on Apr 27, 2007 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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

4:07 pm on Apr 27, 2007 (gmt 0)

5+ Year Member



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

Dabrowski

5:08 pm on Apr 27, 2007 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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

7:09 am on Apr 28, 2007 (gmt 0)

5+ Year Member



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

Dabrowski

11:46 am on Apr 28, 2007 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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

4:47 pm on May 1, 2007 (gmt 0)

10+ Year Member



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

Dabrowski

5:26 pm on May 1, 2007 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month