Skip Menu |

This queue is for tickets about the IPC-Cmd CPAN distribution.

Report information
The Basics
Id: 88454
Status: new
Priority: 0/
Queue: IPC-Cmd

People
Owner: Nobody in particular
Requestors: jos [...] dwim.org
Cc:
AdminCc:

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



CC: kane [...] cpan.org, zefram [...] fysh.org, gisle [...] aas.no
Subject: Re: Modification to IPC::Cmd
Date: Thu, 5 Sep 2013 17:00:59 -0700
To: Philip Prindeville <philipp [...] cpan.org>, bug-IPC-Cmd [...] rt.cpan.org
From: Jos Boumans <jos [...] dwim.org>
Hi Philip, that's an interesting suggestion - I've copied bug-IPC-Cmd@rt.cpan.org, so it's tracked inside the bug tracker as well. That'll also give Chris a chance to review it and weigh in his opinion. Cheers, -Jos On 5 Sep 2013, at 16:53, Philip Prindeville wrote: Show quoted text
> Hi Jos, > > I was trying to use Time::HiRes's setitimer() to periodically run a script and collect output, but of course IPC::Cmd::run() uses alarm(), and hence clobbers any previously set interval timer. > > I was wondering if the following could be done? > > Inside ::run, get any pending interval timer with getitimer(ITIMER_REAL) and figure out what the remaining time is. > > Take this delta, and add it to the current time from gettimeofday(). > > When the function completes and is about to return, IFF there had been a pending interval timer, check whether it has expired. If it has, kill ALARM, getpid(). If it hasn't expired, restore the remaining time and repetition interval with setitimer(). > > This effectively implements a "stack" to save the pending interval timer returned by getitimer (if any) and then restores it (adjusting for elapsed time) on exit. > > It would be nice if Time::HiRes implemented the hooks to save and restore the itimer, but that's a "perfect world" scenario. > > Thanks, > > -Philip >
CC: Philip Prindeville <philipp [...] cpan.org>
Subject: Re: [rt.cpan.org #88454] Re: Modification to IPC::Cmd
Date: Thu, 5 Sep 2013 23:30:12 -0700
To: bug-IPC-Cmd [...] rt.cpan.org
From: Jos Boumans <jos [...] dwim.org>
please make sure this gets added to the ticket. Begin forwarded message: Show quoted text
> From: Philip Prindeville <philipp@cpan.org> > Subject: Re: Modification to IPC::Cmd > Date: 5 September 2013 22:31:07 PDT > To: kane@cpan.org > Cc: zefram@fysh.org, gisle@aas.no > > I did a little bit of playing with it, but I'm not sure about its portability outside of linux. > > Also, it wasn't clear if anything special needs to be done to hold signals while we're inside ::run just in case it's being invoked as part of the calling stack of $SIG{ALRM}… so in theory the amount of time left on the clock could be microseconds when the sub-process in ::run completes, and when we restore the interval timer it could fire before ::run finishes cleaning up. > > There are probably smarter people than myself that know the ins and outs of signal handling in Perl in a portable fashion. > > Anyway, here's my patch. > > Like I said, I haven't tried it in corner cases. > > Like in the case of: > > > $SIG{ALRM} = sub { IPC::Cmd::run("slowcommandx", timeout => 5); } > > setitimer(ITIMER_REAL, 4, 0.0001); > > > so ::run's own timeout won't have happened (assuming the process completes in under 5 seconds) the first time, but the second invocation of the sub-block will complete AFTER the recurring interval timer (100usec) would have fired. Or alternatively we could restore the interval timer with just microseconds before it expires… not enough to have the function complete. > > Any thoughts on this? > > Thanks, > > -Philip >

Message body is not shown because sender requested not to inline it.

Show quoted text
> > On Sep 5, 2013, at 5:53 PM, Philip Prindeville <philipp@cpan.org> wrote: >
>> Hi Jos, >> >> I was trying to use Time::HiRes's setitimer() to periodically run a script and collect output, but of course IPC::Cmd::run() uses alarm(), and hence clobbers any previously set interval timer. >> >> I was wondering if the following could be done? >> >> Inside ::run, get any pending interval timer with getitimer(ITIMER_REAL) and figure out what the remaining time is. >> >> Take this delta, and add it to the current time from gettimeofday(). >> >> When the function completes and is about to return, IFF there had been a pending interval timer, check whether it has expired. If it has, kill ALARM, getpid(). If it hasn't expired, restore the remaining time and repetition interval with setitimer(). >> >> This effectively implements a "stack" to save the pending interval timer returned by getitimer (if any) and then restores it (adjusting for elapsed time) on exit. >> >> It would be nice if Time::HiRes implemented the hooks to save and restore the itimer, but that's a "perfect world" scenario. >> >> Thanks, >> >> -Philip >>
>