in reply to perl thread hangs/not spawned

The error is on line 42, obviously. Oh, wait...

It's hard to tell you anything without seeing your code, or even knowing what kind synchronization you use (semaphores? queues?).

If you let the thread sleep for as long as the 13MB download lasts, does the same error occur? Do you actually load the file to memory?

Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: perl thread hangs/not spawned
by arunb (Initiate) on Oct 15, 2009 at 13:24 UTC

    I am not using any synchronzation( no queues, no semaphores). And the second thread is spawned after the file is downloaded completely to the web server.

    In the main while loop, i do the following

    foreach (@connections_pending) { my $fh; my $remote = accept( $fh, $_ ); my ( $port, $iaddr ) = sockaddr_in($remote); my $peeraddress = inet_ntoa($iaddr); my $t = threads->create( \&connection, $fh ); }

    So when the request for file upload comes from front0end, i spawn the thread.

    Now, in the connection subroutine, i check if its a POST method and if so, i call a subroutine to handle that

    sub upload_file { my ( $fh, $req_ ) = @_; my %req = %$req_; my $header_ = $req{HEADER}; my %header = %$header_; my ($file, $desc, $dirpath ) = (undef, undef, undef); my $boundary = trim (form_data_boundary( $header{'content-type'} ) +); my $user_agent = $header{'user-agent'}; # Now i will process the post buffer and copy the file #to local mach +ine into a temp directory. I shall also #receive the filename, destin +ation directory and some #other metadata information. ($file, $desc, $dirpath) = process_POST_buffer($fh, $req_, $boundary); # Then i spawn another thread to do the pre-processing on this file my $t = threads->create( \&pre_process, $file, $desc, $dirpath ); }

    The pre-process thread does this

    sub pre_process { threads->detach(); my ( $file_name, $desc, $dirpath ) = @_; my ( $file1, $file2, $file3 ) = ( getTempFile(), getTempFile(), + getTempFile() ); my $metadata = i_PreProcessor->new( FILENAME => $file_name, SEARCHXMLFILE => $file1, DESCRIPTION => $desc, MAPXMLFILE => $file2, TAGXMLFILE => $file3, DIRNAME => $dirpath ); $metadata->build2(); #delete temp files. my @files = ( $file1, $file2, $file3 ); unlink(@files); threads->exit(); }
    ~Arun