Pcore::Core::Exception
Pharaoh::Core::Sig - signals management for Pharaoh::Core.
This package is part of Pharaoh::Core.
EXPORTS
CORE::GLOBAL::exit
Common exit() family functions behaviour:
threads->exit() and CORE::exit() is unhandled in threads and perform exit according to threads->set_thread_exit_only;
CORE::exit() is unhandled;
SIGNALS
SIGDIE
Standart $SIG{__DIE__} exceptions handler. Use following code to redefined callback:
local $SIG{__DIE__}; # Redefine handler locally, no callback defined, $SIG{__DIE__} will be ignored
local $SIG{__DIE__} = sub { # Ditto with callback defined
...do something...
};
$SIG{__DIE__}
called from eval block produce ERROR log with stack trace and returns;$SIG{__DIE__}
called from NOT eval block produce FATAL log with stack trace and exit from process / thread;__ALRM__
exception from eval ignored;__ALRM__
exception from NOT eval block produce FATAL exception;__EXIT__
exception is ignored totally and can be processed in your code. See CORE::GLOBAL::exit for example;Calling die() in $SIG{__DIE__} will overwrite $@ and exit $SIG{__DIE__} immidiately;
Overriding die will only catch actual calls to die, not run-time errors;
SIGWARN
Standart $SIG{__WARN__} handler. Produce standart log event on WARN level with stack backtace. To avoid call use following in your code:
local $SIG{__WARN__} = sub { }; # Redefine callback locally
local $SIG{__WARN__} = undef; # Restore standart behaviour in current block
SIGALRM
Standart $SIG{ALRM} handler. Produce __ALRM__
exception. To redefine callback use following in your code:
local $SIG{ALRM} = sub { }; # Redefine callback locally
or use this alarm - safe code:
my $orig_alarm = 0;
eval{
$orig_alarm = alarm 5; # Store previous alarm() timer internally
...some code here...
};
alarm $orig_alarm; # Restore previous timer
if($@ =~ /^__ALRM__/){
...do something on alarm...
}
NOTES
If $SIG{ALRM} not defined - process will killed on alarm. SIG{__DIE__} don't handle alarm exception;
Alarm - safe code must restore previous alarm timer at the end of execution. We can't control bad written code in other modules, so be ready that you alarm timers will not work if you use not alarm - safe modules;
alarm() works on MSWin and in threads as expected;
You must remove alarm timer immidiately after end of eval block (not in block), because if evaluated code will die - eval block will be broken and your alarm will not be removed;
alarm() call on MSWin didn't return amount of time remaining for previous timer. So chained timers on MSWin NOT WORKED.