Home > Archive > PERL POE > February 2007 > POE - Catching INT Signals
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
POE - Catching INT Signals
|
|
| Michael Collins 2007-02-22, 4:29 am |
| Here is a question I also posed on perlmonks.org...
(http://www.perlmonks.org/?node_id=601464)
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, that is, it
ends without any fanfare. The last thing I see on the screen before the
kernel ends is this:
!!! Child process PID:6326 reaped:
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
| |
| Rocco Caputo 2007-02-22, 7:24 pm |
| On Feb 22, 2007, at 01:52, Michael Collins wrote:
> 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:
>
> 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.
After reading this a second time, it occurs to me that you aren't
calling $kernel->sig_handled() in your SIGINT handler. If no session
does, then POE will not know you've handled the signal. It'll
continue on to reap your sessions prematurely.
--
Rocco Caputo - rcaputo@pobox.com
|
|
|
|
|