[30581] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1824 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 28 06:09:42 2008

Date: Thu, 28 Aug 2008 03:09:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 28 Aug 2008     Volume: 11 Number: 1824

Today's topics:
        new CPAN modules on Thu Aug 28 2008 (Randal Schwartz)
        Perl forgets variable every other pass in loop??? <usenet@davidfilmer.com>
    Re: Perl forgets variable every other pass in loop??? <attn.steven.kuo@gmail.com>
    Re: Perl forgets variable every other pass in loop??? <someone@example.com>
    Re: Perl forgets variable every other pass in loop??? <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: perl multithreading performance xhoster@gmail.com
        perl threads <nitte.sudhir@gmail.com>
    Re: subprocesses lifecycle <whynot@pozharski.name>
    Re: subprocesses lifecycle <breafk@remove.this.gmail.com>
    Re: Truncate an array when you have a ref to it? <Alexander.Farber@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 28 Aug 2008 04:42:21 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Thu Aug 28 2008
Message-Id: <K6AnqM.K0J@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Badger-0.01
http://search.cpan.org/~abw/Badger-0.01/
Perl Application Programming Toolkit 
----
CGI-Ajax-0.705
http://search.cpan.org/~bpederse/CGI-Ajax-0.705/
a perl-specific system for writing Asynchronous web applications 
----
CatalystX-CRUD-ModelAdapter-DBIC-0.05
http://search.cpan.org/~karman/CatalystX-CRUD-ModelAdapter-DBIC-0.05/
CRUD for Catalyst::Model::DBIC::Schema 
----
CatalystX-CRUD-ModelAdapter-DBIC-0.06
http://search.cpan.org/~karman/CatalystX-CRUD-ModelAdapter-DBIC-0.06/
CRUD for Catalyst::Model::DBIC::Schema 
----
CatalystX-CRUD-YUI-0.003
http://search.cpan.org/~karman/CatalystX-CRUD-YUI-0.003/
YUI for your CatalystX::CRUD view 
----
Class-Data-ConfigHash-0.00002
http://search.cpan.org/~dmaki/Class-Data-ConfigHash-0.00002/
Add Catalyst-Style Config To Your Class 
----
DBD-Pg-2.10.0
http://search.cpan.org/~turnstep/DBD-Pg-2.10.0/
PostgreSQL database driver for the DBI module 
----
DBIx-Class-GeomColumns-0.0.2
http://search.cpan.org/~kokogiko/DBIx-Class-GeomColumns-0.0.2/
Filter of geometry columns to access with WKT 
----
DBIx-Class-TimeStamp-0.06
http://search.cpan.org/~jshirley/DBIx-Class-TimeStamp-0.06/
----
DBIx-Class-UserStamp-0.11
http://search.cpan.org/~jgoulah/DBIx-Class-UserStamp-0.11/
Automatically set update and create user id fields 
----
Data-Transform-SAXBuilder-0.05
http://search.cpan.org/~martijn/Data-Transform-SAXBuilder-0.05/
A filter for parsing XML with XML::LibXML 
----
Data-Transform-SSL-0.01
http://search.cpan.org/~martijn/Data-Transform-SSL-0.01/
SSL in a filter 
----
Deliantra-Client-0.9975
http://search.cpan.org/~mlehmann/Deliantra-Client-0.9975/
----
Filter-SQL-0.08
http://search.cpan.org/~kazuho/Filter-SQL-0.08/
embedded SQL for perl 
----
Finance-Bank-LloydsTSB-1.34
http://search.cpan.org/~aspiers/Finance-Bank-LloydsTSB-1.34/
Check your bank accounts from Perl 
----
GRID-Machine-0.101
http://search.cpan.org/~casiano/GRID-Machine-0.101/
Remote Procedure Calls over a SSH link 
----
Geo-Converter-WKT2KML-0.0.2
http://search.cpan.org/~kokogiko/Geo-Converter-WKT2KML-0.0.2/
Simple converter between WKT and KML 
----
Geo-Converter-WKT2KML-0.0.3
http://search.cpan.org/~kokogiko/Geo-Converter-WKT2KML-0.0.3/
Simple converter between WKT and KML 
----
Geo-Google-StaticMaps-0.1
http://search.cpan.org/~mart/Geo-Google-StaticMaps-0.1/
API for generating URLs for static Google Maps 
----
Getopt-Std-Strict-1.01
http://search.cpan.org/~leocharre/Getopt-Std-Strict-1.01/
----
Graphics-Primitive-Driver-Cairo-0.15
http://search.cpan.org/~gphat/Graphics-Primitive-Driver-Cairo-0.15/
Cairo backend for Graphics::Primitive 
----
HTML-FormFu-ExtJS-0.01
http://search.cpan.org/~perler/HTML-FormFu-ExtJS-0.01/
Render and validate ExtJS forms using HTML::FormFu 
----
HTML-TreeBuilderX-ASP_NET-0.07
http://search.cpan.org/~ecarroll/HTML-TreeBuilderX-ASP_NET-0.07/
Scrape ASP.NET/VB.NET sites which utilize Javascript POST-backs. 
----
Imager-Search-0.10
http://search.cpan.org/~adamk/Imager-Search-0.10/
Locate images inside other images 
----
JS-JSON-0.01
http://search.cpan.org/~stevan/JS-JSON-0.01/
----
JSAN-Librarian-0.03
http://search.cpan.org/~adamk/JSAN-Librarian-0.03/
JavaScript::Librarian adapter for a JSAN installation 
----
JavaScript-Dumper-0.006
http://search.cpan.org/~perler/JavaScript-Dumper-0.006/
Dump JavaScript data structures from Perl objects. Allows unquoted strings and numbers. 
----
JavaScript-Dumper-0.007
http://search.cpan.org/~perler/JavaScript-Dumper-0.007/
----
JavaScript-Dumper-0.008
http://search.cpan.org/~perler/JavaScript-Dumper-0.008/
Dump JavaScript data structures from Perl objects. Allows unquoted strings and numbers. 
----
Kephra-0.3.9_14
http://search.cpan.org/~lichtkind/Kephra-0.3.9_14/
crossplatform, GUI-Texteditor along perllike Paradigms 
----
KinoSearch-0.163
http://search.cpan.org/~creamyg/KinoSearch-0.163/
search engine library 
----
LaTeX-Table-0.9.1
http://search.cpan.org/~limaone/LaTeX-Table-0.9.1/
Perl extension for the automatic generation of LaTeX tables. 
----
Log-Log4perl-1.18
http://search.cpan.org/~mschilli/Log-Log4perl-1.18/
Log4j implementation for Perl 
----
MooseX-Storage-Format-XML-0.02
http://search.cpan.org/~brunorc/MooseX-Storage-Format-XML-0.02/
An XML serialization role 
----
MooseX-Storage-Format-XML-Simple-0.03
http://search.cpan.org/~brunorc/MooseX-Storage-Format-XML-Simple-0.03/
An XML::Simple serialization role 
----
Mvalve-0.00011
http://search.cpan.org/~dmaki/Mvalve-0.00011/
Generic Q4M Powered Message Pipe 
----
Mvalve-0.00012
http://search.cpan.org/~dmaki/Mvalve-0.00012/
Generic Q4M Powered Message Pipe 
----
Net-FSP-0.11
http://search.cpan.org/~leont/Net-FSP-0.11/
An FSP client implementation 
----
Net-SMS-ASPSMS-0.1.0
http://search.cpan.org/~supcik/Net-SMS-ASPSMS-0.1.0/
Interface to ASMSMS services 
----
Net-SPAMerLookup-0.05
http://search.cpan.org/~lushe/Net-SPAMerLookup-0.05/
Perl module to judge SPAMer. 
----
Net-SPAMerLookup-0.06
http://search.cpan.org/~lushe/Net-SPAMerLookup-0.06/
Perl module to judge SPAMer. 
----
PITA-Test-Dummy-Perl5-MI-0.77
http://search.cpan.org/~adamk/PITA-Test-Dummy-Perl5-MI-0.77/
CPAN Test Dummy for testing Module::Install::With 
----
PITA-Test-Image-Qemu-0.41
http://search.cpan.org/~adamk/PITA-Test-Image-Qemu-0.41/
A tiny Qemu test image that only boots and pings 
----
POEIKC-0.02_05
http://search.cpan.org/~suzuki/POEIKC-0.02_05/
A framework to make a daemon or P2P with "PoCo::IKC" 
----
Parse-Stallion-0.04
http://search.cpan.org/~arthur/Parse-Stallion-0.04/
Perl backtracking parser and resultant tree evaluator 
----
Path-Dispatcher-0.01
http://search.cpan.org/~sartak/Path-Dispatcher-0.01/
flexible dispatch 
----
Rose-DBx-Garden-Catalyst-0.09_05
http://search.cpan.org/~karman/Rose-DBx-Garden-Catalyst-0.09_05/
plant Roses in your Catalyst garden 
----
Rose-HTMLx-Form-Related-0.06
http://search.cpan.org/~karman/Rose-HTMLx-Form-Related-0.06/
RHTMLO forms, living together 
----
Term-Pulse-v0.01
http://search.cpan.org/~alec/Term-Pulse-v0.01/
show progress bar in terminal 
----
TheSchwartz-Simple-0.01
http://search.cpan.org/~miyagawa/TheSchwartz-Simple-0.01/
Lightweight TheSchwartz job dispatcher using plain DBI 
----
Unix-Lsof-v0.0.4
http://search.cpan.org/~marcb/Unix-Lsof-v0.0.4/
Wrapper to the Unix lsof utility 
----
Win32-Monitoring-DLLInject-0.05
http://search.cpan.org/~rplessl/Win32-Monitoring-DLLInject-0.05/
Injects Win32 programs with overloaded functions 
----
Win32-Monitoring-Session-0.01
http://search.cpan.org/~rplessl/Win32-Monitoring-Session-0.01/
Find some information on the logon session 
----
subs-auto-0.01
http://search.cpan.org/~vpit/subs-auto-0.01/
Read barewords as subroutine names. 


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


------------------------------

Date: Wed, 27 Aug 2008 16:23:39 -0700
From: David Filmer <usenet@davidfilmer.com>
Subject: Perl forgets variable every other pass in loop???
Message-Id: <VtmdnesjLY9_fCjVRVn_vwA@giganews.com>

Greetings!

Kindly consider this code which illustrates my question:

#!/usr/bin/perl
    use strict;

    my $column_ref = [
       { 'description' => { 'align' => 'left'  } },
       { 'total'       => { 'align' => 'right' } },
    ];
    for (1..6) {
       foreach my $format_ref( @{$column_ref} ) {
          my( $column, $attr_ref ) = each %{ $format_ref };
          print "'$column', '$attr_ref'\t";
       }
       print "\n";
    }
__END__

What I would EXPECT to see from this program is something like this:

    'description', 'HASH(0x8206710)'   'total', 'HASH(0x81fd314)'
    'description', 'HASH(0x8206710)'   'total', 'HASH(0x81fd314)'
    'description', 'HASH(0x8206710)'   'total', 'HASH(0x81fd314)'
    'description', 'HASH(0x8206710)'   'total', 'HASH(0x81fd314)'
    'description', 'HASH(0x8206710)'   'total', 'HASH(0x81fd314)'
    'description', 'HASH(0x816dc28)'   'total', 'HASH(0x8192258)'

But, for some strange reason, Perl seems to "forget" the value of 
$column_ref on every OTHER pass.  What I ACTUALLY see is this:

    'description', 'HASH(0x816dc28)'        'total', 'HASH(0x8192258)'
     '', ''  '', ''
    'description', 'HASH(0x816dc28)'        'total', 'HASH(0x8192258)'
    '', ''  '', ''
    'description', 'HASH(0x816dc28)'        'total', 'HASH(0x8192258)'
    '', ''  '', ''

Can anyone tell me what is happening to $column_ref???

Thanks!

-- 
David Filmer (http://DavidFilmer.com)
The best way to get a good answer is to ask a good question.


------------------------------

Date: Wed, 27 Aug 2008 17:42:34 -0700 (PDT)
From: "attn.steven.kuo@gmail.com" <attn.steven.kuo@gmail.com>
Subject: Re: Perl forgets variable every other pass in loop???
Message-Id: <b7cf3de0-d4ac-4e75-9f97-c0397e1aaf1c@b30g2000prf.googlegroups.com>

On Aug 27, 4:23 pm, David Filmer <use...@davidfilmer.com> wrote:
> Greetings!
>
> Kindly consider this code which illustrates my question:
>
> #!/usr/bin/perl
>     use strict;
>
>     my $column_ref = [
>        { 'description' => { 'align' => 'left'  } },
>        { 'total'       => { 'align' => 'right' } },
>     ];
>     for (1..6) {
>        foreach my $format_ref( @{$column_ref} ) {
>           my( $column, $attr_ref ) = each %{ $format_ref };
>           print "'$column', '$attr_ref'\t";
>        }
>        print "\n";
>     }
> __END__
>
> What I would EXPECT to see from this program is something like this:
>
>     'description', 'HASH(0x8206710)'   'total', 'HASH(0x81fd314)'
>     'description', 'HASH(0x8206710)'   'total', 'HASH(0x81fd314)'
>     'description', 'HASH(0x8206710)'   'total', 'HASH(0x81fd314)'
>     'description', 'HASH(0x8206710)'   'total', 'HASH(0x81fd314)'
>     'description', 'HASH(0x8206710)'   'total', 'HASH(0x81fd314)'
>     'description', 'HASH(0x816dc28)'   'total', 'HASH(0x8192258)'
>
> But, for some strange reason, Perl seems to "forget" the value of
> $column_ref on every OTHER pass.  What I ACTUALLY see is this:
>
>     'description', 'HASH(0x816dc28)'        'total', 'HASH(0x8192258)'
>      '', ''  '', ''
>     'description', 'HASH(0x816dc28)'        'total', 'HASH(0x8192258)'
>     '', ''  '', ''
>     'description', 'HASH(0x816dc28)'        'total', 'HASH(0x8192258)'
>     '', ''  '', ''
>
> Can anyone tell me what is happening to $column_ref???
>



You're missing the inner most loop.  To obtain the output you
desired, you should have written:

for (1 .. 6) {
  for my $format_ref (@$column_ref) {
      while (my ($c, $a) = each %$format_ref)
      {
          print "'$c', '$a'\t";
      }
  }
  print "\n";
}


See 'perldoc -f each' -- you're incrementally
going through an iterator and printing the contents
of the null array that's returned when the
iterator is exhausted (on every other line).

--
Hope this helps,
Steven


------------------------------

Date: Thu, 28 Aug 2008 00:50:15 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Perl forgets variable every other pass in loop???
Message-Id: <bDmtk.125188$nD.111811@pd7urf1no>

David Filmer wrote:
> 
> Kindly consider this code which illustrates my question:
> 
> #!/usr/bin/perl
>    use strict;
> 
>    my $column_ref = [
>       { 'description' => { 'align' => 'left'  } },
>       { 'total'       => { 'align' => 'right' } },
>    ];
>    for (1..6) {
>       foreach my $format_ref( @{$column_ref} ) {
>          my( $column, $attr_ref ) = each %{ $format_ref };
>          print "'$column', '$attr_ref'\t";
>       }
>       print "\n";
>    }
> __END__
> 
> What I would EXPECT to see from this program is something like this:
> 
>    'description', 'HASH(0x8206710)'   'total', 'HASH(0x81fd314)'
>    'description', 'HASH(0x8206710)'   'total', 'HASH(0x81fd314)'
>    'description', 'HASH(0x8206710)'   'total', 'HASH(0x81fd314)'
>    'description', 'HASH(0x8206710)'   'total', 'HASH(0x81fd314)'
>    'description', 'HASH(0x8206710)'   'total', 'HASH(0x81fd314)'
>    'description', 'HASH(0x816dc28)'   'total', 'HASH(0x8192258)'
> 
> But, for some strange reason, Perl seems to "forget" the value of 
> $column_ref on every OTHER pass.  What I ACTUALLY see is this:
> 
>    'description', 'HASH(0x816dc28)'        'total', 'HASH(0x8192258)'
>     '', ''  '', ''
>    'description', 'HASH(0x816dc28)'        'total', 'HASH(0x8192258)'
>    '', ''  '', ''
>    'description', 'HASH(0x816dc28)'        'total', 'HASH(0x8192258)'
>    '', ''  '', ''
> 
> Can anyone tell me what is happening to $column_ref???

That is the way that each() works.

You need to either do it like this:

for ( 1 .. 6 ) {
     for my $format_ref ( @$column_ref ) {
         while ( my ( $column, $attr_ref ) = each %$format_ref ) {
             print "'$column', '$attr_ref'\t";
         }
     }
     print "\n";
}

Or like this:

for ( 1 .. 6 ) {
     for my $format_ref ( @$column_ref ) {
         for my $column ( keys %$format_ref ) {
             print "'$column', '$format_ref->{$column}'\t";
         }
     }
     print "\n";
}



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


------------------------------

Date: Wed, 27 Aug 2008 20:28:24 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Perl forgets variable every other pass in loop???
Message-Id: <pjiho5xeis.ln2@goaway.wombat.san-francisco.ca.us>

On 2008-08-28, John W. Krahn <someone@example.com> wrote:
>
> That is the way that each() works.

From perldoc -f each:

When the hash is entirely read, a null array is
returned in list context (which when assigned pro-
duces a false (0) value), and "undef" in scalar
context.  The next call to "each" after that will
start iterating again.  

So the ''forgotten'' entries are the null arrays.

--keith



-- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information



------------------------------

Date: 27 Aug 2008 22:17:29 GMT
From: xhoster@gmail.com
Subject: Re: perl multithreading performance
Message-Id: <20080827181732.258$Ab@newsreader.com>

dniq00@gmail.com wrote:
> Hello, oh almighty perl gurus!
>
> I'm trying to implement multithreaded processing for the humongous
> amount of logs that I'm currently processing in 1 process on a 4-CPU
> server.

Start 4 processes, telling each one to work on a different log file.
Either do this from the command line, or implement it with fork or system,
depending on how automatic it all has to be.

> Anyway, currently all this is done in a single process, which parses
> approx. 30000 lines per second.

If you just check for GET (and then ignore the result), how many lines per
second would it do?

> The CPU usage for this process is
> 100%, so the bottleneck is in the parsing part.
>
> I have changed the script to use threads + threads::shared +
> Thread::Queue. I read data from logs like this:
>
> Code
> until( $no_more_data ) {
>         my @buffer;
>         foreach( (1..$buffer_size) ) {
>                 if( my $line = <> ) {
>                         push( @buffer, $line );
>                 } else {
>                         $no_more_data = 1;
>                         $q_in->enqueue( \@buffer );
>                         foreach( (1..$cpu_count) ) {
>                                 $q_in->enqueue( undef );
>                         }
>                         last;
>                 }
>         }
>         $q_in->enqueue( \@buffer ) unless $no_more_data;
> }
>
> Then, I create $cpu_count threads, which does something like this:

What do you mean "then"?  If you wait until all lines are enqueued before
you create the consumer threads, your entire log file will be in memory!

>
> Code
> sub parser {
>         my $counters = {};
>         while( my $buffer = $q_in->dequeue() ) {
>                 foreach my $line ( @{ $buffer } ) {
>                     # do its thing
>                 }
>         }
>         return $counters;
> }

When $counters is returned, what do you do with it?  That could be
another synchronization bottleneck.

>
> Everything works fine, HOWEVER! It's all so damn slow! It's only 10%
> faster than single-process script, consumes about 2-3 times more
> memory and about as much times more CPU.

That doesn't surprise me.

> I've also tried abandoning the Thread:Queue and just use
> threads::shared with lock/cond_wait/cond_signal combination, without
> much success.

This also doesn't surprise me. Synchronizing shared access is hard and
often slow.


>
> I've tried to play with $cpu_count and $buf_size, and found that after
> $buf_size > 1000 doesn't make much difference, and $cpu_count > 2
> actually makes things a lot worse.
>
> Any ideas why in the world it's so slow? I did some research and
> couldn't find a lot of info, other than the way I do it pretty much
> the way it should be done, unless I'm missing something...
>
> Hope anybody can enlighten me...

If you post fully runnable dummy code, and a simple program which
generates log-file data to put through it, I'd probably couldn't resist the
temptation to play around with it and find the bottlenecks.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


------------------------------

Date: Thu, 28 Aug 2008 02:02:38 -0700 (PDT)
From: kath <nitte.sudhir@gmail.com>
Subject: perl threads
Message-Id: <496e3859-9d30-49bb-b593-f12271a870c2@l42g2000hsc.googlegroups.com>

Hi,
Background:
I have task of calculating dependencies of project(s) of a scenario.
Dependency calculation is done using an external command. Since this
dependency calculation time depends on how big is the project is, it
is difficult to guess how much dependency calculation of a scenario(a
set of projects) takes. To overcome this i am using 'threads' module
to create thread and ask each thread to do the dependency calculation.

I have many scenarios currently and i calculate dependency foreach
scenario. I create one thread for each project in the scenario and
wait for all threads to finish, to take on next scenario. Because i
know 'Perl ithreads are not lightweight!', i am using carefully, in
the sense, I'm not using any shared variables between threads. Each
thread will do dependency calculation, which will produces an output
in a file separately. Later i parse those files to get dependency list
for each project.

Problem:
Sometimes* the script waits forever or the script just hangs. That is
waiting for threads. And cant continue with other scenario.

[code]
#this way i create threads
#foreach scenario() ...{
map {my $th = threads->create(\&worker, $_)} @$proj_arr; #proj_arr has
projects of a scenario
# ...}

# This is how i wait for all threads to finish its job
print "waiting for threads to finish";
map {my $k = $_->join} threads->list;
[/code]

Is there a way i can overcome this? Or my perception about cause for
the problem is right? Because from the log i see, only 'waiting for
threads to finish' at last and script will continue. This is happens
only sometimes. Most of the times the script executes fine.

Atleast i want to be informed about the 'script is not responding or
hanged', because the script is scheduled there will be not be any clue
unless and otherwise, myself has to go and check.

Hope i could explain the problem clearly. I am using 'perl, v5.8.8
built for MSWin32-x86-multi-thread'


Thanks in advance,
katharnakh.


------------------------------

Date: Thu, 28 Aug 2008 00:04:04 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: subprocesses lifecycle
Message-Id: <43sgo5xts2.ln2@carpet.zombinet>

Matthieu Imbert <breafk@remove.this.gmail.com> wrote:
*SKIP*

> Currently, when I detect the timeout, I call die "error message". the
> message is displayed, but the script does not return until subprocesses
> finish (this may take several minutes, depending on what the
> subprocesses do).

perl -mIO::Pipe -wle '
$pipe = IO::Pipe->new;
if(fork) {
        $pipe->reader;
        sleep 1;
        die; };
$pipe->writer;
open $h, q|</etc/passwd|;
while($l = <$h>) {
        print $pipe $l;
        sleep 1; }
' ; ps -O ppid t ; sleep 40 ; ps -O ppid t
Died at -e line 6.
  PID  PPID S TTY          TIME COMMAND
12782     1 S pts/1    00:00:00 perl -mIO::Pipe -wle ?$pipe = IO::Pipe->new;
12783 29996 R pts/1    00:00:00 ps -O ppid t
29996 29991 S pts/1    00:00:11 bash
  PID  PPID S TTY          TIME COMMAND
12785 29996 R pts/1    00:00:00 ps -O ppid t
29996 29991 S pts/1    00:00:11 bash

See that?  There's no problem with dieing (I won't comment why the
system needs more that half a minute to get rid off child (kernel?
shell?  init?  panic...); YMMV).

However you say that you have a problem.  I suppose you have to
investigate why your script attempts to collect zombies.  It should not
unless told so.

> Is there a way to force the end of all subprocesses when calling die?

Second.  No one can kill process which hangs in syscall till the process
gets out into userspace.  So you'd be better finding why you collect.

-- 
Torvalds' goal for Linux is very simple: World Domination


------------------------------

Date: Thu, 28 Aug 2008 10:06:31 +0200
From: Matthieu Imbert <breafk@remove.this.gmail.com>
Subject: Re: subprocesses lifecycle
Message-Id: <48b65c88$0$1188$426a74cc@news.free.fr>

Eric Pozharski wrote:
> perl -mIO::Pipe -wle '
> $pipe = IO::Pipe->new;
> if(fork) {
>         $pipe->reader;
>         sleep 1;
>         die; };
> $pipe->writer;
> open $h, q|</etc/passwd|;
> while($l = <$h>) {
>         print $pipe $l;
>         sleep 1; }
> ' ; ps -O ppid t ; sleep 40 ; ps -O ppid t
> Died at -e line 6.
>   PID  PPID S TTY          TIME COMMAND
> 12782     1 S pts/1    00:00:00 perl -mIO::Pipe -wle ?$pipe = IO::Pipe->new;
> 12783 29996 R pts/1    00:00:00 ps -O ppid t
> 29996 29991 S pts/1    00:00:11 bash
>   PID  PPID S TTY          TIME COMMAND
> 12785 29996 R pts/1    00:00:00 ps -O ppid t
> 29996 29991 S pts/1    00:00:11 bash
> 
> See that?  There's no problem with dieing (I won't comment why the
> system needs more that half a minute to get rid off child (kernel?
> shell?  init?  panic...); YMMV).
> 
> However you say that you have a problem.  I suppose you have to
> investigate why your script attempts to collect zombies.  It should not
> unless told so.
> 
>> Is there a way to force the end of all subprocesses when calling die?
> 
> Second.  No one can kill process which hangs in syscall till the process
> gets out into userspace.  So you'd be better finding why you collect.
> 

Hi Eric, here is how i understand things:

In your example code, the child process stays alive after the end of
parent process. As there are probably 30 to 40 lines in /etc/passwd and
it sleeps 1 second for each line, it's not surprising that it takes
about half a minute to end and die.

This confirms the fact that perl does not kill subprocesses when calling
die.

But it does not explain why in your example the parent script returns
immediately when calling die, while in my case the parent script waits
for children to end before returning. I thought that this could be
related to the way you create child processes (with fork), whereas i
create then with open. But this little test script returns immediately:

perl -e '
open (CHILD,"sleep 30 |");
die "byebye";
'

So the problem must come from something else. i have to understand why
it behaves differently in my first script (i'll try to isolate the
simplest reproducible demonstration code of the problem).

Currently, as a workaround, i added code that finds all subprocesses of
my script and sends TERM, then wait 10s, then send KILL to all of them


Matthieu


------------------------------

Date: Wed, 27 Aug 2008 23:11:22 -0700 (PDT)
From: "A. Farber" <Alexander.Farber@gmail.com>
Subject: Re: Truncate an array when you have a ref to it?
Message-Id: <8b0408be-6faa-4c6b-817d-2222718dea60@c58g2000hsc.googlegroups.com>

On Aug 27, 11:01=A0pm, Ted Zlatanov <t...@lifelogs.com> wrote:
> On Wed, 27 Aug 2008 13:34:00 -0700 (PDT) "A. Farber" <Alexander.Far...@gm=
ail.com> wrote:
>
> AF> =A0 =A0 =A0 =A0 $aref =3D $self->{CHAT}->[0];
> AF> =A0 =A0 =A0 =A0 push @response, 'chat0=3D' . join '', @$aref;
> AF> =A0 =A0 =A0 =A0 $self->{CHAT}->[0] =3D [];
>
> Actually it assigns a new value to that reference. =A0The old array still
> exists with the full contents if you have another reference to it (check
> $aref, for instance).
>
> AF> I wonder if I can truncate that array by
> AF> using the $aref ? Something like $#xxxx =3D -1;
>
> @$aref =3D ();
>
> or, equivalently,
>
> @{$self->{CHAT}->[0]} =3D ();

Oh, you're right. Thank you!


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 1824
***************************************


home help back first fref pref prev next nref lref last post