Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit edc7621

Browse files
authored
Fix PythonException GC (#400)
Since PythonException doesn't inherit from PyObject, need to reapply the same fix as from gh:365. Seen mostly on PY27/Travis on PyTuple tests. Enable PyTuple tests for PY27/Travis
1 parent d86880a commit edc7621

File tree

2 files changed

+1
-24
lines changed

2 files changed

+1
-24
lines changed

src/embed_tests/pytuple.cs

-23
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,6 @@ namespace Python.EmbeddingTest
66
{
77
public class PyTupleTest
88
{
9-
/// <summary>
10-
/// Tests set-up. Being used to skip class on Travis/PY27
11-
/// </summary>
12-
/// <remarks>
13-
/// FIXME: Fails on Travis/PY27: All tests below (unless otherwise stated)
14-
/// Fatal Python error: auto-releasing thread-state, but no thread-state for this thread
15-
/// Stacktrace:
16-
/// at (wrapper managed-to-native) Python.Runtime.Runtime.PyGILState_Release (intptr)
17-
/// at Python.Runtime.PythonEngine.ReleaseLock (intptr)
18-
/// at Python.Runtime.PythonException.Dispose ()
19-
/// at Python.Runtime.PythonException.Finalize ()
20-
/// at (wrapper runtime-invoke) object.runtime_invoke_virtual_void__this__ (object,intptr,intptr,intptr)
21-
/// </remarks>
22-
[SetUp]
23-
public void SetUp()
24-
{
25-
if (Environment.GetEnvironmentVariable("TRAVIS") == "true" &&
26-
Environment.GetEnvironmentVariable("TRAVIS_PYTHON_VERSION") == "2.7")
27-
{
28-
Assert.Ignore("Fails on Travis/PY27: Fatal Python error: auto-releasing thread-state, but no thread-state for this thread");
29-
}
30-
}
31-
329
/// <summary>
3310
/// Test IsTupleType without having to Initialize a tuple.
3411
/// PyTuple constructor use IsTupleType. This decouples the tests.

src/runtime/pythonexception.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void Dispose()
140140
{
141141
if (!disposed)
142142
{
143-
if (Runtime.Py_IsInitialized() > 0)
143+
if (Runtime.Py_IsInitialized() > 0 && !Runtime.IsFinalizing)
144144
{
145145
IntPtr gs = PythonEngine.AcquireLock();
146146
Runtime.XDecref(_pyType);

0 commit comments

Comments
 (0)