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

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to