No subject
Mon Aug 2 21:23:14 CDT 2004
How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
Release 5 of Perl added the END block, which can be used to simulate
atexit(). Each package's END block is called when the program or
thread ends (see perlmod manpage for more details).
For example, you can use this to make sure your filter program
managed
to finish its output without filling up the disk:
END {
close(STDOUT) || die "stdout close failed: $!";
}
The END block isn't called when untrapped signals kill the program,
though, so if you use END blocks you should also use
use sigtrap qw(die normal-signals);
Perl's exception-handling mechanism is its eval() operator. You can
use eval() as setjmp and die() as longjmp. For details of this, see
the section on signals, especially the time-out handler for a
blocking
flock() in "Signals" in perlipc or the section on ``Signals'' in the
Camel Book.
If exception handling is all you're interested in, try the excep-
tions.pl library (part of the standard perl distribution).
If you want the atexit() syntax (and an rmexit() as well), try the
AtExit module available from CPAN.
Brian Michalk <http://www.michalk.com>
Life is what you make of it ... never wish you had done something.
Aviator, experimental aircraft builder, motorcyclist, SCUBA diver
musician, home-brewer, entrepreneur and mostly single
> -----Original Message-----
> From: austin-admin at mail.pm.org [mailto:austin-admin at mail.pm.org]On
> Behalf Of Evan Harris
> Sent: Monday, May 12, 2003 2:07 PM
> To: Austin Perlmongers
> Subject: APM: Using threads in perl
>
>
>
> I'm using a threaded copy of perl 5.8.0 to write a sendmail milter using
> Sendmail::Milter from cpan. The milter interface creates a long-running
> perl that spawns seperate threads to handle callbacks from the milter
> interface.
>
> According to the docs, those threads are periodically recycled and
> respawned. However, I've noticed that when that happens, the
> threads don't
> seem to release/close a global dbi handle I'm using from within the milter
> callbacks, and is over time creating dozens of connections to the database
> that never go away unless I restart the milter, and it eventually exhausts
> the db connection pool.
>
> Does anyone know of something I can setup that is specific to perl threads
> where I can register a function to be called immediately before a
> thread is
> destroyed? I would have that function explicitly close the db connection,
> and hopefully that would solve my problem.
>
> Thanks.
>
> Evan
>
> _______________________________________________
> Austin mailing list
> Austin at mail.pm.org
> http://mail.pm.org/mailman/listinfo/austin
>
More information about the Austin
mailing list