Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Timing out a child process on Windows

47 views
Skip to first unread message

David Cantrell

unread,
May 28, 2013, 10:53:05 AM5/28/13
to win32-...@perl.org
I've got a wee problem with one of my modules on Windows:
http://www.cpantesters.org/cpan/report/6c50e2a4-6c0f-1014-988b-f0c2162c787f

However, I don't have a Windows licence, nor do I know how to drive
Windows, nor, to be blunt, do I particularly want to learn. But if
anyone could help me make my code more portable I'd be very grateful.

The code in my module that has the problem starts at line 186 here:
https://github.com/DrHyde/perl-modules-CPAN-ParseDistribution/blob/master/lib/CPAN/ParseDistribution.pm#L186

Its purpose is to run arbitrary code in a Safe.pm compartment, and to
have that compartment time out if it takes more than 5 seconds. It does
this using Parallel::ForkManager to run the Safe compartment in a child
process. The child may return data to the parent via some magic in
Parallel::ForkManager which is effectively a wrapper around Storable.

Stuff that assumes a Unixy world, other than fork()ing in the first
place, is the kill() on line 194.

I presume that the 17-ish lines starting at 186 will need to be
completely different for Windows.

If anyone can help, the beers are on me at the next YAPC we're both at!

--
David Cantrell | Bourgeois reactionary pig

Human Rights left unattended may be removed,
destroyed, or damaged by the security services.

Jan Dubois

unread,
May 28, 2013, 1:04:18 PM5/28/13
to David Cantrell, win32-...@perl.org
On Tue, May 28, 2013 at 7:53 AM, David Cantrell <da...@cantrell.org.uk> wrote:
> I've got a wee problem with one of my modules on Windows:
> http://www.cpantesters.org/cpan/report/6c50e2a4-6c0f-1014-988b-f0c2162c787f
>
> However, I don't have a Windows licence, nor do I know how to drive
> Windows, nor, to be blunt, do I particularly want to learn. But if
> anyone could help me make my code more portable I'd be very grateful.
>
> The code in my module that has the problem starts at line 186 here:
> https://github.com/DrHyde/perl-modules-CPAN-ParseDistribution/blob/master/lib/CPAN/ParseDistribution.pm#L186
>
> Its purpose is to run arbitrary code in a Safe.pm compartment, and to
> have that compartment time out if it takes more than 5 seconds. It does
> this using Parallel::ForkManager to run the Safe compartment in a child
> process. The child may return data to the parent via some magic in
> Parallel::ForkManager which is effectively a wrapper around Storable.
>
> Stuff that assumes a Unixy world, other than fork()ing in the first
> place, is the kill() on line 194.
>
> I presume that the 17-ish lines starting at 186 will need to be
> completely different for Windows.
>
> If anyone can help, the beers are on me at the next YAPC we're both at!

Sorry, no time to help, but if you find somebody with the time, then
CPAN::Reporter may have some code you can borrow:

https://github.com/dagolden/cpan-reporter/blob/master/lib/CPAN/Reporter.pm#L1269

Unfortunately you won't be able to use fork(); you'll have to create a
new process inside a "Job", where the Job can have a timeout...

Cheers,
-Jan

David Cantrell

unread,
May 29, 2013, 1:20:01 PM5/29/13
to win32-...@perl.org
On Tue, May 28, 2013 at 03:53:05PM +0100, David Cantrell wrote:

> The code in my module that has the problem starts at line 186 here:
> https://github.com/DrHyde/perl-modules-CPAN-ParseDistribution/blob/master/lib/CPAN/ParseDistribution.pm#L186

I've factored the Unix-specific code into a separate module now, so if
anyone gets a chance to look at it, it should be easier to fix.

--
David Cantrell | Nth greatest programmer in the world

People from my sort of background needed grammar schools to
compete with children from privileged homes like ... Tony Benn
-- Margaret Thatcher

Victor Miasnikov

unread,
May 30, 2013, 6:29:42 AM5/30/13
to David Cantrell, win32-...@perl.org

Hi!

> On Tue, May 28, 2013 at 03:53:05PM +0100, David Cantrell wrote:
>
>> The code in my module that has the problem starts at line 186 here:
>> https://github.com/DrHyde/perl-modules-CPAN-ParseDistribution/blob/master/lib/CPAN/ParseDistribution.pm#L186
>
> I've factored the Unix-specific code into a separate module now, so if
> anyone gets a chance to look at it, it should be easier to fix.


Ok,
for All who not have time open 1-10 URLs, see _related_ content:

http://www.cpantesters.org/cpan/report/6c50e2a4-6c0f-1014-988b-f0c2162c787f
==
From: Christian Walde
Subject: FAIL CPAN-ParseDistribution-1.5 v5.16.0 Windows (Win32)
Date: 2013-05-24T23:14:17Z

. . .

Locally applied patches:
ActivePerl Build 1600 [295879]

( VVM: see later about ActivePerl 5.16.3 )

. . .

Output from 'C:\Perl16\site\bin\dmake.exe test':

C:\Perl16\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib\lib', 'blib\arch')" t/*.t
'tar' is not recognized as an internal or external command,
operable program or batch file.
no AUTHOR_TESTING, skipping a bunch of tests
Attempt to free unreferenced scalar: SV 0x3a39a4c, Perl interpreter: 0x2f23974 at
C:\Perl16\cpan\build\Parallel-ForkManager-1.03-NooagN/blib/lib/Parallel/ForkManager.pm line 511.

( VVM: see later "CORE::exit($x || 0);" )
. . .

Attempt to free unreferenced scalar: SV 0x3bba3dc, Perl interpreter: 0x1c8bb24 at
C:\Perl16\cpan\build\Parallel-ForkManager-1.03-NooagN/blib/lib/Parallel/ForkManager.pm line 511.
t/fileindexer.t ...
Dubious, test returned 15 (wstat 3840, 0xf00)
Failed 9/38 subtests
(less 2 skipped subtests: 27 okay)
==




https://github.com/DrHyde/perl-modules-CPAN-ParseDistribution/blob/master/lib/CPAN/ParseDistribution/Unix.pm
==
package CPAN::ParseDistribution::Unix;
. . .
sub _run {
. . .
my $fork_manager = Parallel::ForkManager->new(1);
}
. . .
==




http://search.cpan.org/~szabgab/Parallel-ForkManager-1.03/lib/Parallel/ForkManager.pm
=}
http://cpansearch.perl.org/src/SZABGAB/Parallel-ForkManager-1.03/lib/Parallel/ForkManager.pm
===
. . .
# On ActiveState Perl 5.6/Win32
. . .
sub finish {
my ($s, $x, $r)=@_;

if ( $s->{in_child} ) {
if (defined($r)) { # store the child's data structure
my $storable_tempfile = File::Spec->catfile($s->{tempdir}, 'Parallel-ForkManager-' . $s->{parent_pid} . '-' . $$ .
'.txt');
my $stored = eval { return &store($r, $storable_tempfile); };

# handle Storables errors, IE logcarp or carp returning undef, or die (via logcroak or croak)
if (not $stored or $@) {
warn(qq|The storable module was unable to store the child's data structure to the temp file
"$storable_tempfile": | . join(', ', $@));
}
}
CORE::exit($x || 0); # VVM: this is Parallel/ForkManager.pm line 511. affected Attempt to free unreferenced
scalar: SV 0x3bba3dc
}
if ($s->{max_proc} == 0) { # max_proc == 0
$s->on_finish($$, $x ,$s->{processes}->{$$}, 0, 0, $r);
delete $s->{processes}->{$$};
}
return 0;
}
. . .
===






VVM>> ActiveState 5.16.0 ? Why not 5.16.3? Why not S.B.Perl?

D.C.> You mean why did my original email point at a test report from perl 5.16.0?
D.C.>Because, errm, that's where the test report came from.
D.C.> I don't control what build of perl people use.
+
D.C.> . . .could just attempt to debug solely by using the CPAN-testers but . . .


IMHO, need simply answer to "perl people"/tester ( i.e. to Christian Walde) :
-- please send result of testing with Strawberry Perl 5.18 and/or 5.16.3
+
-- look like, tar.exe not exist:
==
'tar' is not recognized as an internal or external command,
operable program or batch file.
==






Best regards, Victor Miasnikov
Blog: http://vvm.blog.tut.by/

David Cantrell

unread,
May 31, 2013, 11:24:07 AM5/31/13
to win32-...@perl.org
On Thu, May 30, 2013 at 01:29:42PM +0300, Victor Miasnikov wrote:
>
> Hi!
>
> >On Tue, May 28, 2013 at 03:53:05PM +0100, David Cantrell wrote:
> >
> >>The code in my module that has the problem starts at line 186 here:
> >> https://github.com/DrHyde/perl-modules-CPAN-ParseDistribution/blob/master/lib/CPAN/ParseDistribution.pm#L186
> >
> >I've factored the Unix-specific code into a separate module now, so if
> >anyone gets a chance to look at it, it should be easier to fix.
>
>
> Ok,
> for All who not have time open 1-10 URLs, see _related_ content:
>
> http://www.cpantesters.org/cpan/report/6c50e2a4-6c0f-1014-988b-f0c2162c787f

> Output from 'C:\Perl16\site\bin\dmake.exe test':
>
> C:\Perl16\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test_harness(0,
> 'blib\lib', 'blib\arch')" t/*.t
> 'tar' is not recognized as an internal or external command,
> operable program or batch file.
> no AUTHOR_TESTING, skipping a bunch of tests

This is not relevant. That's the tests detecting that you don't have
tar installed and thus skipping all the tests that require it.

> Attempt to free unreferenced scalar: SV 0x3a39a4c, Perl interpreter:
> 0x2f23974 at
> C:\Perl16\cpan\build\Parallel-ForkManager-1.03-NooagN/blib/lib/Parallel/ForkManager.pm line 511.
>
> ( VVM: see later "CORE::exit($x || 0);" )

Here's the details of what's happening in the tests:
https://gist.github.com/wchristian/dcace83dc70011ae47ca

So I think that these are just warnings and can (for now) be ignored.

> t/fileindexer.t ...
> Dubious, test returned 15 (wstat 3840, 0xf00)
> Failed 9/38 subtests

The message "failed 9/38 subtests" is a bit misleading. It actually
appears to mean that something is crashing horribly at about line 147 of
this file - there are nine tests remaining to be run at that point:
https://metacpan.org/source/DCANTRELL/CPAN-ParseDistribution-1.5/t/fileindexer.t

This makes sense, as trying to parse the Acme-BadExample distribution is
where it tests the magic for having the child process time out.

> VVM>> ActiveState 5.16.0 ? Why not 5.16.3? Why not S.B.Perl?
>
> D.C.> You mean why did my original email point at a test report from perl
> 5.16.0?
> D.C.>Because, errm, that's where the test report came from.
> D.C.> I don't control what build of perl people use.
> +
> D.C.> . . .could just attempt to debug solely by using the CPAN-testers
> but . . .
>
>
> IMHO, need simply answer to "perl people"/tester ( i.e. to Christian Walde)
> :
> -- please send result of testing with Strawberry Perl 5.18 and/or 5.16.3

Here <http://tinyurl.com/l6am97l> are several other identical test failures
on various versions of perl on Windows.

--
David Cantrell | Official London Perl Mongers Bad Influence

Hail Caesar! Those about to vi ^[ you!
0 new messages