Skip to content

Commit 3c8e67b

Browse files
committed
Improve handling of exceptions in signal handlers
1 parent 700fd06 commit 3c8e67b

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

src/core/IronPython.Modules/signal.cs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -495,27 +495,26 @@ public virtual void SetPyHandler(int signalnum, object value)
495495
protected void CallPythonHandler(int signum, object? handler) {
496496
if (handler is null) return;
497497

498-
if (handler == default_int_handler) {
499-
// We're dealing with the default_int_handlerImpl which we
500-
// know doesn't care about the frame parameter
501-
default_int_handlerImpl(signum, null);
502-
return;
503-
} else {
504-
// We're dealing with a callable matching PySignalHandler's signature
505-
try {
506-
PySignalHandler temp = (PySignalHandler)Converter.ConvertToDelegate(handler,
507-
typeof(PySignalHandler));
508-
509-
if (SignalPythonContext.PythonOptions.Frames) {
510-
temp.Invoke(signum, SysModule._getframeImpl(null,
511-
0,
512-
SignalPythonContext._mainThreadFunctionStack));
513-
} else {
514-
temp.Invoke(signum, null);
515-
}
516-
} catch (Exception ex) {
517-
System.Console.WriteLine(SignalPythonContext.FormatException(ex));
498+
try {
499+
if (handler == default_int_handler) {
500+
// We're dealing with the default_int_handlerImpl which we
501+
// know doesn't care about the frame parameter
502+
default_int_handlerImpl(signum, null);
503+
} else {
504+
// We're dealing with a callable matching PySignalHandler's signature
505+
PySignalHandler temp = (PySignalHandler)Converter.ConvertToDelegate(handler,
506+
typeof(PySignalHandler));
507+
508+
if (SignalPythonContext.PythonOptions.Frames) {
509+
temp.Invoke(signum, SysModule._getframeImpl(null,
510+
0,
511+
SignalPythonContext._mainThreadFunctionStack));
512+
} else {
513+
temp.Invoke(signum, null);
514+
}
518515
}
516+
} catch (Exception ex) {
517+
SignalPythonContext.DomainManager.SharedIO.ErrorWriter.WriteLine(SignalPythonContext.FormatException(ex));
519518
}
520519
}
521520

0 commit comments

Comments
 (0)