[Catalyst] Proper way to perform cleanups on server shutdown?

John Napiorkowski jjn1056 at yahoo.com
Wed Jul 11 18:34:36 GMT 2007


--- "Jonathan T. Rockway" <jon at jrock.us> wrote:

> On Wed, Jul 11, 2007 at 09:03:29AM -0700, John
> Napiorkowski wrote:
> > I can demonstrate this by placing an END block in
> my
> > root modules (the "MyApp.pm" module)
> > 
> > END {
> >   print "got END BLOCK!\n";
> > }
> > 
> > This will never run under the conditions I have
> > described.
> > 
> > HOWEVER, if I set SIG handlers manually like so:
> > 
> > $SIG{INT} = sub { print "got INT!\n" };
> > $SIG{TERM} = sub { print "got TERM!\n" };
> > 
> > END {
> >   print "got END BLOCK!\n";
> > }
> > 
> > Then the END block does run.
> 
> Is this different from what you would expect?
> 
> try:
> 
>   $ perl -e 'END { print "going away\n" }; sleep 1
> while(1);' 
>   ^C
>   $ _
> 
> compared to:
> 
>   $ perl -e 'END { print "going away\n" }'
>   going away
>   $ _ 
> 
> >From what I've observed, a signal won't trigger END
> blocks even
> outside of Catalyst.
> 
> Regards,
> Jonathan Rockway

To be honest I am not sure what should happen.  Your
example makes total sense, but I don't understand why
an INT|TERM signal doesn't always cause the
application to quit immediately and fail any END
blocks.  In the case I have I see that it fails the
END blocks unless I add some signal handlers in the
global space.  So I am at a lose to understand that.

I've spent a lot of spare time since I started this
threat more than 2 weeks ago trying to figure it out
but it seems that signal handling is quite arcane,
particularly if you need to worry about older Perls
and Perls on non Unix platforms.

Pressing Ctrl-C is how the tutorial tells me to exit
the development server (when running foregrounded). 
However this will definitely cause trouble with code
that uses END blocks, particularly for cleanup.  So
what I am trying to figure out is a good way to
canonically signal a catalyst application to
gracefully stop or restart.  This would be a way that
would respect any cleanup handling.

We have a run command for Catalyst::Engine, perhaps it
would be good to have a stop and restart here as well?
 Or maybe saying this displays too much ignorance on
my part, but I have to start somewhere :)

I guess I would like to help to try and clarify and
document the behavior.  I just could use some guidance
from people with more intimate understanding of the
system.  Maybe this is something more for the
development list?  

Thanks!

John

> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo:
> http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive:
>
http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
> 



      ____________________________________________________________________________________
Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/ 



More information about the Catalyst mailing list