Changeset 32581 for main/trunk/greenstone2
- Timestamp:
- 2018-11-07T19:04:30+13:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/gssql.pm
r32580 r32581 33 33 use DBI; # the central package for this module used by GreenstoneSQL Plugout and Plugin 34 34 35 #$SIG{INT} = sub { die "Caught a sigint $!" }; 36 #$SIG{TERM} = sub { die "Caught a sigterm $!" }; 37 #$SIG{KILL} = sub { die "Caught a sigkill $!" }; 38 39 40 $SIG{INT} = \&finish_signal_handler; 41 $SIG{TERM} = \&finish_signal_handler; 42 $SIG{KILL} = \&finish_signal_handler; 43 44 sub finish_signal_handler { 45 my ($sig) = @_; # one of INT|KILL|TERM 46 die "Caught a $sig signal $!"; # will call destructor 47 } 35 48 ############################## 36 49 … … 94 107 } 95 108 96 109 # On die(), an object's destructor is called. 110 # See https://www.perl.com/article/37/2013/8/18/Catch-and-Handle-Signals-in-Perl/ 111 # We want to ensure we've closed the db connection in such cases. 112 # "Itâs common to call die when handling SIGINT and SIGTERM. die is useful because it will ensure that Perl stops correctly: for example Perl will execute a destructor method if present when die is called, but the destructor method will not be called if a SIGINT or SIGTERM is received and no signal handler calls die." 113 # https://perldoc.perl.org/perlobj.html#Destructors 114 sub DESTROY { 115 my $self = shift; 116 117 if (${^GLOBAL_PHASE} eq 'DESTRUCT') { 118 if ($_dbh_instance) { 119 print STDERR "XXXXXXXX Global Destruct: Disconnecting from database\n"; 120 $_dbh_instance->disconnect or warn $_dbh_instance->errstr; 121 $_dbh_instance = undef; 122 $ref_count = 0; 123 } 124 return; 125 } 126 } 97 127 98 128 #################################
Note:
See TracChangeset
for help on using the changeset viewer.