sub walktimer { #Sleep for 180 seconds, upon completion execute SQL to change OK_OPEN back to all zero for $showcasenum my $showcasenum = $_[0]; debug("Launched walking timer thread for $showcasenum"); $SIG{'KILL'} = sub { threads->exit(); }; my $count = $walktime; sleep( 1 ) while --$count; ### Wake once per second for $walktime seconds to allow the "signal handler" to respond to any pending "signals". if( threads->is_detached()) { threads->exit(); } my $dbh = DBI->connect('dbi:mysql:alarm:databasehost','username','password') or die "Connection Error: $DBI::errstr\n"; my $sql = "update Showcases set OK_OPEN=0 WHERE SC_NUM = ?"; my $sth = $dbh->prepare($sql) or die "Can't prepare $sql: $dbh->errstr\n"; $sth->execute($showcasenum) or die "SQL Error: $DBI::errstr\n"; $dbh->disconnect; debug("Walking thread for $showcasenum is expiring..."); threads->detach(); }