File tree 3 files changed +24
-0
lines changed
3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ and other `PyObject` derived types when called from Python.
36
36
details about the cause of the failure
37
37
- ` clr.AddReference ` no longer adds ".dll" implicitly
38
38
- ` PyIter(PyObject) ` constructor replaced with static ` PyIter.GetIter(PyObject) ` method
39
+ - Python runtime can no longer be shut down if the Python error indicator is set, as it would have unpredictable behavior
39
40
- BREAKING: Return values from .NET methods that return an interface are now automatically
40
41
wrapped in that interface. This is a breaking change for users that rely on being
41
42
able to access members that are part of the implementation class, but not the
Original file line number Diff line number Diff line change @@ -351,6 +351,12 @@ public static void Shutdown()
351
351
{
352
352
return ;
353
353
}
354
+ if ( Exceptions . ErrorOccurred ( ) )
355
+ {
356
+ throw new InvalidOperationException (
357
+ "Python error indicator is set" ,
358
+ innerException : PythonException . PeekCurrentOrNull ( out _ ) ) ;
359
+ }
354
360
// If the shutdown handlers trigger a domain unload,
355
361
// don't call shutdown again.
356
362
AppDomain . CurrentDomain . DomainUnload -= OnDomainUnload ;
Original file line number Diff line number Diff line change @@ -75,6 +75,23 @@ internal static PythonException FetchCurrentRaw()
75
75
=> FetchCurrentOrNullRaw ( )
76
76
?? throw new InvalidOperationException ( "No exception is set" ) ;
77
77
78
+ internal static Exception ? PeekCurrentOrNull ( out ExceptionDispatchInfo ? dispatchInfo )
79
+ {
80
+ using var _ = new Py . GILState ( ) ;
81
+
82
+ Runtime . PyErr_Fetch ( out var type , out var value , out var traceback ) ;
83
+ Runtime . PyErr_Restore (
84
+ new NewReference ( type , canBeNull : true ) . StealNullable ( ) ,
85
+ new NewReference ( value , canBeNull : true ) . StealNullable ( ) ,
86
+ new NewReference ( traceback , canBeNull : true ) . StealNullable ( ) ) ;
87
+
88
+ var err = FetchCurrentOrNull ( out dispatchInfo ) ;
89
+
90
+ Runtime . PyErr_Restore ( type . StealNullable ( ) , value . StealNullable ( ) , traceback . StealNullable ( ) ) ;
91
+
92
+ return err ;
93
+ }
94
+
78
95
internal static Exception ? FetchCurrentOrNull ( out ExceptionDispatchInfo ? dispatchInfo )
79
96
{
80
97
dispatchInfo = null ;
You can’t perform that action at this time.
0 commit comments