Perl destructor not being called? Here's why

If you’re using a Perl destructor method (‘DESTROY’, ‘DEMOLISH’) it may not be called if the Perl process is terminated abruptly by a signal. To fix this, just add the sigtrap pragma to your program:

use sigtrap qw/die normal-signals/;

Now if the program receives a SIGINT or SIGTERM, the Perl process will die and call the destructor.

To read more on signal handlers see our article: Catch and Handle Signals in Perl


This article was originally posted on PerlTricks.com.

Tags

David Farrell

David is the editor of Perl.com. An organizer of the New York Perl Meetup, he works for ZipRecruiter as a software developer, and sometimes tweets about Perl and Open Source.

Browse their articles

Feedback

Something wrong with this article? Help us out by opening an issue or pull request on GitHub