Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Children with Win32::Process when dying

by spurperl (Priest)
on Jun 07, 2006 at 05:32 UTC ( #553965=perlquestion: print w/replies, xml ) Need Help??
spurperl has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,

I have a non-Tk script that opens an external program with Win32::Process and talks to it via sockets. When my script exits normally - during runtime (by either ending its run or with an explicit 'die' or 'exit') everything is fine. However, when the script is killed by the perl interpreter because of some runtime-discovered mistake (like trying to access @{$arr} when $arr turns out not to be an array reference), the child process keeps running after my scipt ends, which is very annoying.

How can I solve this problem ?


2006-06-07 Retitled by holli, as per Monastery guidelines
Original title: 'Children with Wi32::Process when dying'

  • Comment on Children with Win32::Process when dying

Replies are listed 'Best First'.
Re: Children with Win32::Process when dying
by syphilis (Chancellor) on Jun 07, 2006 at 06:22 UTC
    Perhaps in the "non-Tk script" you can include an END{} block - something like:
    END{$obj->Kill($exitcode) if $obj->GetExitCode() == STILL_ACTIVE};
    For that to work you'll need to be using version 0.10 of Win32::Process and you'll need to load the module as:
    use Win32::Process (STILL_ACTIVE);
    Even with earlier versions of Win32::Process there's probably a way of doing it - assuming that the END{} block is the way to go - which I've not properly tested. In fact you might even find it sufficient to simply:
    which would work for earlier versions of Win32::Process, too.

    Also check the syntax of the GetExitCode() call (if you find you need to use it). The docs have it written as
    but supplying an argument doesn't smell right to me.

      The simple END {} cleanup helped. I wonder how it could have slipped from my mind :-)

      Thanks a lot

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://553965]
Approved by monkfan
[erix]: then you might as well send that patch to the DBIC guys :)
[Corion]: erix: Yeah, I just found that it has no documentation at all on how to circumvent/ eliminate "1+n SELECTs" by building a local hash... I guess I have to make ->has_many do the hash lookup instead of doing the SQL query. But as the problem ...
[Corion]: ... has only manifested itself so far through the puzzled questions of other bystanders, I won't go deeper at this time. But the DBIx::Class documentation could well do with a document on how to make "it" (that is, ORMs in general) faster ;)
[Corion]: I find that DBIx::Class, like most ORMs makes things easy until they become performance critical and then makes it horribly hard to change things because the design is highly inflexible if you don't already know about the problems of 1+n :-/
[choroba]: that's why I don't like similar libraries. They pretend you don't have to learn SQL, but in the end, you have to learn how SQL plus to overcome their own limitations
[Corion]: "Just write the proper SQL beforehand" is of course the appropriate solution, but if you did that, you wouldn't/couldn't use DBIx::Class either. At least not in an obvious (to me) way.
choroba scratches a "how"
[Corion]: choroba: Exactly... But maybe that's just because I'm old and grumpy ;)

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2017-09-25 11:09 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (279 votes). Check out past polls.