Re: session not stopping

Andreas Altergott <[email protected]>
Newsgroups gmane.comp.lang.perl.poe
Organization MIRA Consulting GmbH
Message-ID <[email protected]>
Hi,

Olivier Mengué wrote:
> Do you send the 'shutdown' event to the
> POE::Compononent::Win32::ChangeNotify session in your SIGINT handler?

Yes, I do.  Here's the promised minimal source example, which still does
reproduce the error.  After running for about 10 minutes it did not
terminate after a sigint (CTRL+C).  Hope someone can reproduce this mistake.

Again, I'm using Windows XP SP3 32 Bit, Perl 5.10.1 from ActiveState.
POE 1.006 from ActiveStates repository as an PPM.  Also from the
repository is POE::Component::Win32::ChangeNotify 1.20.

#!/usr/bin/perl
########################################################################
# loop.pl

use strict;
use warnings;

#sub POE::Kernel::TRACE_REFCNT() { 1 }

use File::Spec;
use POE qw (Component::Win32::ChangeNotify);

my %opts = ('dir' => '.', 'delay' => 1);

sub _start {
    my ($kernel, $heap) = @_[KERNEL, HEAP];

    $kernel->sig('INT' => 'sigint');

    $heap->{'wdog'} = POE::Component::Win32::ChangeNotify->spawn(
        'alias' => 'wdog'
    );

    $kernel->post(
        'wdog',
        'monitor',
        {
            'path'    => $opts{'dir'},
            'event'   => 'wdog',
            'filter'  => 'FILE_NAME',
            'subtree' => 1
        }
    );

    $kernel->delay('scan', $opts{'delay'});
}

sub scan {
    my ($kernel, $heap) = @_[KERNEL, HEAP];

    print("working...\n");

    $kernel->delay('scan', $opts{'delay'});
}

sub sigint {
    my ($kernel, $heap) = @_[KERNEL, HEAP];

    print("sigint received\n");

    if (defined($heap->{'wdog'})) {
        print("wdog terminating\n");
        $kernel->post('wdog' => 'shutdown');
    }

    $kernel->delay('scan');

    $kernel->sig_handled();
}

sub wdog {
    my ($kernel, $heap, $argh) = @_[KERNEL, HEAP, ARG0];

    if ($argh->{'error'}) {
        print("can not sentinel $argh->{'path'}: $argh->{'error'}\n");
    } else {
        print("new file in $argh->{'path'}\n");
    }
}

$opts{'dir'} = File::Spec->rel2abs($opts{'dir'});

POE::Session->create(
    inline_states => {
        '_start'    => \&_start,
        'scan'      => \&scan,
        'sigint'    => \&sigint,
        'wdog'      => \&wdog
    }
);

POE::Kernel->run();
exit(0);

# EOF
########################################################################

Any suggestions?  I'm new to POE, so feel free to criticise me :-)


Thanks,
Andreas
signature.asc (application/pgp-signature, 260 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrDnN4ACgkQImDrLy4cAN9YXgCgx4Mu58sf2av/SlPiZ69YcSsF
LiAAnRsUzOrNfr0raG6rSD+ZTki0dL8j
=YbPJ
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.