Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Parallel-ForkManager CPAN distribution.

Report information
The Basics
Id: 35659
Status: open
Priority: 0/
Queue: Parallel-ForkManager

People
Owner: Nobody in particular
Requestors: peter [...] makholm.net
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Let run_on_wait callback
It would be nice if the run_on_wait callback could abort the operation, for example by returning a false value. Use cases would be having the a timeout on how long a single job would wait or having Parallel::ForkManager respect a signal handler setting a flag to abort the process: my $abort = 0; $SIG{HUP} = sub { $abort = 1 }; $pm->run_on_wait( sub { return ! $abort } ); while (not $abort) { my $job = shift @queue; $pm->start($job) and next; ... ... ... $pm->finish; } The attached patch implements this by having $pm->start return '0 but true' if the process was aborted. Beware that this changes the interface in a not quite compatible way.
Subject: ForkManager.patch
--- /usr/share/perl5/Parallel/ForkManager.pm 2006-06-15 03:28:44.000000000 +0200 +++ ForkManager.pm 2008-05-06 11:41:07.908057188 +0200 @@ -281,7 +281,8 @@ die "Cannot start another process while you are in the child process" if $s->{in_child}; while ($s->{max_proc} && ( keys %{ $s->{processes} } ) >= $s->{max_proc}) { - $s->on_wait; + $s->on_wait + or return "0 but true"; $s->wait_one_child(defined $s->{on_wait_period} ? &WNOHANG : undef); }; $s->wait_children; @@ -360,13 +361,15 @@ } sub on_wait { my ($s)=@_; + my $result = 1; if(ref($s->{on_wait}) eq 'CODE') { - $s->{on_wait}->(); + $result = $s->{on_wait}->(); if (defined $s->{on_wait_period}) { local $SIG{CHLD} = sub { } if ! defined $SIG{CHLD}; select undef, undef, undef, $s->{on_wait_period} }; }; + return $result; }; sub run_on_start { my ($s,$code)=@_;
From: dlux [...] dlux.hu
Hi, I got your patch, thank you for that. I'll take a closer look at it as soon as I have more time for this! Cheers, dLux On Tue May 06 05:55:16 2008, pmakholm wrote: Show quoted text
> It would be nice if the run_on_wait callback could abort the operation, > for example by returning a false value. > > Use cases would be having the a timeout on how long a single job would > wait or having Parallel::ForkManager respect a signal handler setting a > flag to abort the process: > > my $abort = 0; > $SIG{HUP} = sub { $abort = 1 }; > > $pm->run_on_wait( sub { return ! $abort } ); > > while (not $abort) { > my $job = shift @queue; > > $pm->start($job) and next; > > ... ... ... > > $pm->finish; > } > > The attached patch implements this by having $pm->start return '0 but > true' if the process was aborted. Beware that this changes the interface > in a not quite compatible way.
Hi, I've checked the patch, but I don't really want to break the compatibility. I'd add another callback next to the on_wait, like on_wait2 or some more sophisticated name. What do you think? Balázs
Subject: Re: [rt.cpan.org #35659] Let run_on_wait callback
Date: Wed, 26 Nov 2008 11:31:07 +0100
To: bug-Parallel-ForkManager [...] rt.cpan.org
From: Peter Makholm <peter [...] makholm.net>
"Szabo, Balazs via RT" <bug-Parallel-ForkManager@rt.cpan.org> writes: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=35659 > > > Hi, > > I've checked the patch, but I don't really want to break the compatibility.
I fully understand that you don't want to break compatibility. Adding a new callback is fine, but don't use a sophisticated name. Let it be clear that it does the same, but in a slightly more expressible way. //Makholm
From: fbicknel [...] nc.rr.com
I found that you can do this: 164 do { 165 $kid = $pm->wait_one_child (&WNOHANG); 166 } while $kid > 0; Maybe what's needed is a simple documentation update? It looks like ->wait_one_child was not intended to be an 'external' method, but it works just like waitpid() but will also issue the appropriate callbacks.
On Fri Feb 12 13:56:00 2010, fbicknel wrote: Show quoted text
> I found that you can do this: > > 164 do { > 165 $kid = $pm->wait_one_child (&WNOHANG); > 166 } while $kid > 0; > > Maybe what's needed is a simple documentation update? It looks like > ->wait_one_child was not intended to be an 'external' method, but it > works just like waitpid() but will also issue the appropriate callbacks.
Hi, What I'd do is to have a method on the Parallel::ForkManager object, which, if called, will abort the procedure (and from that point, start will always return false). If you have time to implement it (please add documentation also), I'm fine with implementing the patch. Balzs
Hi, Are you planning to go forward with it? Balázs On Fri Feb 12 15:10:38 2010, DLUX wrote: Show quoted text
> On Fri Feb 12 13:56:00 2010, fbicknel wrote:
> > I found that you can do this: > > > > 164 do { > > 165 $kid = $pm->wait_one_child (&WNOHANG); > > 166 } while $kid > 0; > > > > Maybe what's needed is a simple documentation update? It looks like > > ->wait_one_child was not intended to be an 'external' method, but it > > works just like waitpid() but will also issue the appropriate callbacks.
> > Hi, > > What I'd do is to have a method on the Parallel::ForkManager object, > which, if called, will abort the procedure (and from that point, start will > always return false). > > If you have time to implement it (please add documentation also), I'm > fine with implementing the patch. > > Balzs