_stop state isn't called on child when parent gets Ctrl-C (EasyDBI session still active)

--00163692050156259e046970194a
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Hello once again POE world,

*I have a problem with a child daemon process not being killed when I hit
Ctrl-C for the parent.  All other children are reaped but one remains. This
child happens to be the one using EasyDBI.
*I have noticed that when I hit Ctrl-C......I don't see the _stop event
called for any of the spawned children.  This _stop event is what
calls $kernel->post(
'EasyDBI', 'shutdown' => 'NOW' );
*I'm assuming that the reason the child stays around is because the EasyDBI
session is still alive.

1)Parent uses wheel::run to spawn workers (database worker only one that
stays alive)

2)Database worker child spawns EasyDbi session as well as other sessions

3)Everything runs normally then I hit Ctrl-C which kills the parent process,
then shows all the other children reaped but hangs on the final one
!!! Child process PID:17843 reaped:
!!! Child process PID:17842 reaped:
.....hangs here

4)A second Ctrl-C ends the program (with child process still running)
# ps aux | grep perl
root     17841  2.7  1.0 153992 21276 pts/5    S    17:18   0:00
/usr/bin/perl ./WorkerDbd  (This process should be gone)


(PARENT Daemon)
##################################################
foreach my $key (keys %$workers ){
    foreach my $worker ( @{$workers->{$key}} ){
        print "The worker is $worker\n";
        POE::Session->create(
            inline_states => {
                  _start           => \&on_start,
                  _child           => \&_child,
                  got_child_stdout => \&on_child_stdout,
                  got_child_stderr => \&on_child_stderr,
                  got_child_close  => \&on_child_close,
                  got_child_signal => \&on_child_signal,
                  _stop            => \&_stop
            },
            args => [$worker]
          );
    }
}

sub on_start {
    my ( $kernel, $session, $heap, $worker ) = @_[ KERNEL, SESSION, HEAP,
ARG0 ];
    my $child = POE::Wheel::Run->new(
              Program => [ "./$worker" ],
              StdoutEvent  => "got_child_stdout",
              StderrEvent  => "got_child_stderr",
              CloseEvent   => "got_child_close",
        );

    $_[KERNEL]->sig_child($child->PID, "got_child_signal");

    # Wheel events include the wheel's ID.
    $_[HEAP]{children_by_wid}{$child->ID} = $child;

    # Signal events include the process ID.
    $_[HEAP]{children_by_pid}{$child->PID} = $child;

    print(
      "Child pid ", $child->PID,
      " started as wheel ", $child->ID, ".\n"
    );
}

##########################################################
(Database Worker CHILD Daemon)
POE::Kernel->stop();
POE::Component::IKC::Responder->spawn();

POE::Component::EasyDBI->spawn( # or new(), witch returns an obj
        alias       => 'EasyDBI',
        dsn         => 'DBI:mysql:database=foobaz;host=localhost;port=3306',
        username    => 'username',
        password    => 'password',
        options     => {
            AutoCommit => 0,
        },
);

App::Database->__spawn();

POE::Kernel->run();

(Package)
App::Database
sub __spawn {
    my $class = shift;

    my $addr  = $class->IP   || '127.0.0.1';
    my $port  = $class->PORT || 5667;
    my $trace = $class->TRACE || 0;
    my $debug = $class->DEBUG || 0;
    my $client = $class->ALIAS || "Client$$";
    my $workername = $client . 'Worker';

    ## spawn the ikc client with unique workername
    my $server = POE::Component::IKC::Client->spawn(
        ip         => $addr,
        port       => $port,
        name       => $workername,

        on_connect => sub {
             $_[HEAP]->{channel} = $poe_kernel->get_active_session()->ID;
             print STDERR Dumper($_[HEAP]);
            POE::Session->create(

                package_states =>
                  ## extract all subroutines that don't start with "__"
                  ## and allocate them as states:
                  [
                     (__PACKAGE__) => [ do {
                            no strict 'refs';
                            grep { !/^__/ and defined &$_ } keys %{
__PACKAGE__ . "::" };
                          } ],
                     ($class)       => [ $class->SUBSCRIBE_METHODS ]

                  ],
                ## pass args into _start:
                args => [$class,@_],
                options => { trace => $trace, debug => $debug },

            );
        }
    );

    return $server;
}

sub _start {
      my ( $kernel, $session, $heap, $class, $arg1 ) = @_[ KERNEL, SESSION,
HEAP, ARG0, ARG1 ];

      my $states;
      my $alias = $class->ALIAS;

       # name this session
       if($class){
        $kernel->alias_set($alias);
        $kernel->post( 'IKC', 'publish', $alias, [$class->SUBSCRIBE_METHODS]
);
        $class->__startup($kernel,$session,$heap);
       }
}

sub _stop {
    my ( $kernel, $session, $heap, $arg ) = @_[ KERNEL, SESSION, HEAP, ARG0
];
    print STDERR "STOP WAS CALLED FOR THE WORKER TEMPLATE $session->ID\n";
    $kernel->post( 'EasyDBI', 'shutdown' => 'NOW' );
    $kernel->post(IKC=>'retract' );
    $kernel->yield('__shutdown');
}

--00163692050156259e046970194a--
0
josh803316
5/9/2009 12:48:09 AM
perl.poe 1573 articles. 0 followers. Follow

1 Replies
872 Views

Similar Articles

[PageSpeed] 54

--00504501411f696357046970d07b
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

*This definitely has to do with the open EasyDBI session

I tested this by shutting down the EasyDBI session from inside the child
manually before a Ctrl-C and indeed the shutdown works fine with no orphaned
processes.

(Called this before Control-C)
sub my_test_handler_before_ctrl_c{
    POE::Kernel->post( 'EasyDBI', 'shutdown' => 'NOW' );
}

........program running.......
(CONTROL-C HERE)
(All 3 children reaped)
MAIN STOP CALLED
!!! Child process PID:18268 reaped:
!!! Child process PID:18267 reaped:
!!! Child process PID:18266 reaped:


So the real question is, how do I handle this correctly......Do I handle
this in the parent by looking for open sessions or do I handle this on the
child side by adding signal handlers?

Any and all suggestions welcome.  Thanks in advance for any advice

On Fri, May 8, 2009 at 5:48 PM, Josh803316 <josh803316@gmail.com> wrote:

> Hello once again POE world,
>
> *I have a problem with a child daemon process not being killed when I hit
> Ctrl-C for the parent.  All other children are reaped but one remains. This
> child happens to be the one using EasyDBI.
> *I have noticed that when I hit Ctrl-C......I don't see the _stop event
> called for any of the spawned children.  This _stop event is what calls $kernel->post(
> 'EasyDBI', 'shutdown' => 'NOW' );
> *I'm assuming that the reason the child stays around is because the EasyDBI
> session is still alive.
>
> 1)Parent uses wheel::run to spawn workers (database worker only one that
> stays alive)
>
> 2)Database worker child spawns EasyDbi session as well as other sessions
>
> 3)Everything runs normally then I hit Ctrl-C which kills the parent
> process, then shows all the other children reaped but hangs on the final one
> !!! Child process PID:17843 reaped:
> !!! Child process PID:17842 reaped:
> ....hangs here
>
> 4)A second Ctrl-C ends the program (with child process still running)
> # ps aux | grep perl
> root     17841  2.7  1.0 153992 21276 pts/5    S    17:18   0:00
> /usr/bin/perl ./WorkerDbd  (This process should be gone)
>
>
> (PARENT Daemon)
> ##################################################
> foreach my $key (keys %$workers ){
>     foreach my $worker ( @{$workers->{$key}} ){
>         print "The worker is $worker\n";
>         POE::Session->create(
>             inline_states => {
>                   _start           => \&on_start,
>                   _child           => \&_child,
>                   got_child_stdout => \&on_child_stdout,
>                   got_child_stderr => \&on_child_stderr,
>                   got_child_close  => \&on_child_close,
>                   got_child_signal => \&on_child_signal,
>                   _stop            => \&_stop
>             },
>             args => [$worker]
>           );
>     }
> }
>
> sub on_start {
>     my ( $kernel, $session, $heap, $worker ) = @_[ KERNEL, SESSION, HEAP,
> ARG0 ];
>     my $child = POE::Wheel::Run->new(
>               Program => [ "./$worker" ],
>               StdoutEvent  => "got_child_stdout",
>               StderrEvent  => "got_child_stderr",
>               CloseEvent   => "got_child_close",
>         );
>
>     $_[KERNEL]->sig_child($child->PID, "got_child_signal");
>
>     # Wheel events include the wheel's ID.
>     $_[HEAP]{children_by_wid}{$child->ID} = $child;
>
>     # Signal events include the process ID.
>     $_[HEAP]{children_by_pid}{$child->PID} = $child;
>
>     print(
>       "Child pid ", $child->PID,
>       " started as wheel ", $child->ID, ".\n"
>     );
> }
>
> ##########################################################
> (Database Worker CHILD Daemon)
> POE::Kernel->stop();
> POE::Component::IKC::Responder->spawn();
>
> POE::Component::EasyDBI->spawn( # or new(), witch returns an obj
>         alias       => 'EasyDBI',
>         dsn         =>
> 'DBI:mysql:database=foobaz;host=localhost;port=3306',
>         username    => 'username',
>         password    => 'password',
>         options     => {
>             AutoCommit => 0,
>         },
> );
>
> App::Database->__spawn();
>
> POE::Kernel->run();
>
> (Package)
> App::Database
> sub __spawn {
>     my $class = shift;
>
>     my $addr  = $class->IP   || '127.0.0.1';
>     my $port  = $class->PORT || 5667;
>     my $trace = $class->TRACE || 0;
>     my $debug = $class->DEBUG || 0;
>     my $client = $class->ALIAS || "Client$$";
>     my $workername = $client . 'Worker';
>
>     ## spawn the ikc client with unique workername
>     my $server = POE::Component::IKC::Client->spawn(
>         ip         => $addr,
>         port       => $port,
>         name       => $workername,
>
>         on_connect => sub {
>              $_[HEAP]->{channel} = $poe_kernel->get_active_session()->ID;
>              print STDERR Dumper($_[HEAP]);
>             POE::Session->create(
>
>                 package_states =>
>                   ## extract all subroutines that don't start with "__"
>                   ## and allocate them as states:
>                   [
>                      (__PACKAGE__) => [ do {
>                             no strict 'refs';
>                             grep { !/^__/ and defined &$_ } keys %{
> __PACKAGE__ . "::" };
>                           } ],
>                      ($class)       => [ $class->SUBSCRIBE_METHODS ]
>
>                   ],
>                 ## pass args into _start:
>                 args => [$class,@_],
>                 options => { trace => $trace, debug => $debug },
>
>             );
>         }
>     );
>
>     return $server;
> }
>
> sub _start {
>       my ( $kernel, $session, $heap, $class, $arg1 ) = @_[ KERNEL, SESSION,
> HEAP, ARG0, ARG1 ];
>
>       my $states;
>       my $alias = $class->ALIAS;
>
>        # name this session
>        if($class){
>         $kernel->alias_set($alias);
>         $kernel->post( 'IKC', 'publish', $alias,
> [$class->SUBSCRIBE_METHODS] );
>         $class->__startup($kernel,$session,$heap);
>        }
> }
>
> sub _stop {
>     my ( $kernel, $session, $heap, $arg ) = @_[ KERNEL, SESSION, HEAP, ARG0
> ];
>     print STDERR "STOP WAS CALLED FOR THE WORKER TEMPLATE $session->ID\n";
>     $kernel->post( 'EasyDBI', 'shutdown' => 'NOW' );
>     $kernel->post(IKC=>'retract' );
>     $kernel->yield('__shutdown');
> }
>

--00504501411f696357046970d07b--
0
josh803316
5/9/2009 1:39:20 AM
Reply:

Similar Artilces:

I can't get no cache, I can't get no cache. 'Cause I try and I try and I try and, I can't get no, I can't get no cache.
I have fiddled out for days tinkering with the setting in about:config trying to get FireFox 12 to use the disk cache. I have NOT found the trick. This One Trick Pony ain't doing it like it used to up until recently. Pray tell anyone, What information can I share that will point a knowledgeable person to aid me in getting FF to disk.cache? I have also tried restarting FF with add-ons disabled, (There were NOT too many to do this to, so it was quick and easy) Here is my stab at trying to convey the information that MIGHT govern matters Using about:cache Informatio...

Re: I can't get no cache, I can't get no cache. ' Cause I try and I try and I try and, I can't get no, I can't get no cache.
<div>please com e see me about htis<br /> <br /> ------- Original Message f= rom the Global Relay Archive -------<br /> From: Hp &lt;ferd@farkel.net&gt;= <br /> To: "support-firefox@lists.mozilla.org" &lt;support-firefox@lists.mo= zilla.org&gt;<br /> Sent: Sun, 27 May 2012 18:30:18 -0700<br /> Subject: I = can't get no cache, I can't get no cache. 'Cause I try and I try and I try = and, I can't get no, I can't get no cache.<br /> <br /></div> <pre class=3D"gr-maex-body-pre&qu...

Isn't it called Mozilla? It's what the browser I'm using is called.
Name: Keith Email: BIGred1_1965atlivedotcom Product: Firefox Summary: Isn't it called Mozilla? It's what the browser I'm using is called. Comments: I'm HOPING that I can persuade somebody HERE, to install a button in Mozilla. To close the currently viewed window, WITHOUT having to close the entire browser, go check out the ADVANCED browser. It's what I WAS using before I had Mozilla installed/infecting my machine. IF you install the button I'm asking for, I'll consider KEEPING it as my browser, even though I've ALREADY got the A.B. configured....

Konqueror Can't Cut'n'paste with Ctrl C, Ctrl V?
I've been using Kaggregator in KDE-PIM, which uses Konqueror as the browser to go to links from Kaggregator. Unfortunately, Konqueror no longer seems to be able to Copy highlighted material with Ctrl C, the way we've done it for ever. Is this a setting I've missed? Or is this a new "feature" in Konqueror? Thanks, Bob It's working for me Try resetting the settings to defaults in K But it might be more system wide than just K -- Box: openSUSE 11.2 | (KDE4.3.5) | AMD 64 X2 5200+ | nVidia 8500GT | 4GB RAM Lap: openSUSE 11.2 | Pentium Duo T4300 |...

Two things,Why do I keep getting emails that I don't want. can't get rid of them? Why can't I get my email when I am out of town? Or can I?
Name: Ed Leech Email: ELCraftatzoominternetdotnet Product: Thunderbird Summary: Two things,Why do I keep getting emails that I don't want. can't get rid of them? Why can't I get my email when I am out of town? Or can I? Comments: I am getting frusted with all the emails coming in that I do not want, I am using the tools to get thme out but they keep coming. They just use different names or whatever. I have been thinking of just switching to something else but my business intrusts know this email and it is tooo confusing to change. Every time I go out of town on bu...

After a looong night managed to change Session mode from inProc to SQLServer but still can't get the session variables to be saved
Hi,  I ran my Shopping Cart project and somehow everything worked fine(while in inProc), session variables were saved fine. I made some changes to my project and since then keep getting null session variables, no matter what I do. It took me the whole night to figure out how to turn to SQLServer mode,  marked custom classes as 'Serializable' with [Serializable] before the class definition but everything's in vain. Getting the same damned 'nulls' instead of the saved objects. private void Page_Load(object sender, System.EventArgs e)         {...

Messages don't always get sent if computer's date isn't right
I've found that if my computer's date is off by more than some unknown amount, when I send a message it doesn't always really get sent. Yet I don't get an error indication, and the message appears in my Sent folder right along with the rest of my sent messages. Anyone know how much my computer's date can differ from true time before this problem appears? Some of my messages to newsgroups had their dates off by two years, but still got posted. A few minutes ago, I sent two eamils to myself, one with my computer set to September 28, 2009 (one month error)...

AJAX Method isn't getting called
 Hi All,    I am using AJAX to populate a textbox(txtFac) based on the values in a dropdown(ddlyear) and a textbox(txtproj) on click of a button(btnView).Problem is:- The AJAX method isn't called Code in the javascript eh.addEvent($("btnView"), 'click', function() {    fnValidate();}, false);function fnValidate(){                          var varInvtyr = frmGiEiaEdit.document.getElementById("ddlyear");   &...

Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects.
Hi, I get the following error in ASP.NET 2.0 using SQL Server for sessionstate: Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode. What I am doing is: 1) I have an object marked as [Serializable] which is passed into a ArrayList. 2) The ArrayList is past of a codebehind partial class (also maked as serializable)&n...

can't use ctrl+c, ctrl+x, ctrl+v
Can't use short key for copy, cut, paste on window (from opensheet() command), But it work correct when use open() command. Do you have those keys defined as shortcuts on the sheet window menu? -- Regards, Millard[TeamSybase] <Poss> wrote in message news:9C2D5A2235A616EC0069C10385256B6E.0069C11985256B6E@webforums... > Can't use short key for copy, cut, paste on window (from opensheet() > command), But it work correct when use open() command. ...

Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'
 Hi,We are trying to implement Network loading for our asp.net (1.1) application for which we are storing the session in State Server.Following is the error is thrown while page is rendered when ever is a DTO is stored in to SEssion in any of the page.Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer' Following the code I written for DTO (C# Asp.net 1.1).     using System;    using System.Runtime.Serializa...

Thunderbird still getting mail automatically when not set to, but isn't when set to.
I have 3 accounts (all 3 are IMAP) and I have them set up the following way. -Acct(1) Checks for mail every 10 minutes -Acct(2) Checks for mail every 10 minutes -Acct(3) Does Not Check for mail However, this morning I awoke and checked thunderbird and had the follwoing -Acct(1) Checked for mail and had new messages ready for me. -Acct(2) Did NOT check for mail and showed no messages, but when I manually checked, there were new messages downloaded. -Acct(3) Checked for mail and had new messages ready for me. Anyone know what's up with this? -- SeaMonkey 1.1.2 Multi...

closing a tab-page with 'ctrl+F4' isn't possible
Name: Joeri Puttevils Email: joeridotputtevilsatantwerpendotbe Product: Firefox Summary: closing a tab-page with 'ctrl+F4' isn't possible Comments: Firefox 3.5B99 / Windows (xp+SP3) The keyboard shortcut key CTRL+F4 to close a tab-page doesn't work. It has been replaced with CTRL+w (like in the linux edition) I hope this changes in the final release to be able to use the same shortcut keys for all programs in Windows. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1b99) Gecko/20090605 Firefox/3.5b99 From URL: http://hendrix.mo...

2010: Can't register - can't download the software - can't register until I have the software
I have active maintenance on Rad Studio: From: Vicky Rassmisaengthong [mailto:Vicky.Rassmisaengthong@EMBARCADERO.COM] Sent: Wednesday, February 25, 2009 1:58 PM To: rgrossman Cc: amer.supportadmin@codegear.com; Ashley Cosentino Subject: Software Assurance Support for Tech III Inc PO# Credit Card Dear Embarcadero Technologies Support Customer, Welcome! You have been registered as the primary contact on support account number AM####### Herewith we confirm your Embarcadero Technologies support agreement covering: Qty 1 RAD Studio Enterprise Named User licens...

Web resources about - _stop state isn't called on child when parent gets Ctrl-C (EasyDBI session still active) - perl.poe

Resources last updated: 11/28/2015 4:13:15 PM