Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

POE - Catching INT Signals

by mercutio_viz (Scribe)
on Feb 22, 2007 at 00:43 UTC ( [id://601464]=perlquestion: print w/replies, xml ) Need Help??

mercutio_viz has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed Monks,

I am searching for a way to catch and handle a Control-C when using multiple POE sessions. I have successfully used the snippet from the POE Cookbook to actually catch the INT signal in each of my Sessions:

inline_states => { _connected => sub { my ($kernel, $session) = @_[KERNEL, SESSION]; ## Handle control-C $kernel->sig( INT => 'event_sigint' ); ... } # inline_states ... event_sigint => sub { my ($kernel, $session) = @_[KERNEL, SESSION]; print STDERR "Caught Control-C, shutting down gracefully.\ +n"; $kernel->yield("Shutdown",2,'Received break from user'); }, # event_sigint

In all but one of my sessions I simply catch the signal and print to STDERR a simple message giving the session alias. The above snippet is in only one of my sessions and I want to use it to do the graceful shutdown.

However, I am using POE::Component::SimpleDBI, which uses POE::Wheel::Run to fork a child process that does the 'heavy-lifting' as the POD puts it. What is happening is that somewhere in POE's reaping of the child process(es) created by POE::Component::SimpleDBI, the POE kernel itself is (or seems to be) stopping in its tracks.

Things I have tried:

#1 - manually adding an INT handler to SimpleDBI.pm
#2 - perusing kernel.pm and signals.pm for clues

I confess to the monks that this challenge is beyond me and I humbly submit the question for your review: is there a way to have POE reap the child process without dying immediately thereafter, allowing me to yield a shutdown subroutine to do the cleanup and exit?

Many thanks,

-MC

Replies are listed 'Best First'.
Re: POE - Catching INT Signals
by rcaputo (Chaplain) on Feb 22, 2007 at 03:31 UTC

    Can you be more specific regarding this "stopping in its tracks"? Does it exit, hang, or crash? Are any diagnostic messages shown?

    POE's mailing list might be a better place to discuss this. There's a current thread about DBI and POE, and at least two DBI component authors read and post there.

      I'll post at the POE mailing list as well. Thanks for a great module!

      -MC

        FYI, it was pretty simple:
        The signal handler needs this line:

        $kernel->sig_handled();
        Without telling the kernel that the signal has been handled it continues to reap the various POE sessions as part of its natural response to a Control-C being caught.

        -MC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://601464]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found