Skip to content

Commit 647bc8a

Browse files
committed
Merge branch 'master' into weakref-support
2 parents 53ad8d9 + 6f1219f commit 647bc8a

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

README.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ pythonnet - Python.NET
55

66
|gh shield| |appveyor shield|
77

8-
|license shield| |pypi package version| |conda-forge version| |python supported shield|
8+
|license shield|
9+
10+
|pypi package version| |conda-forge version| |python supported shield|
11+
12+
|nuget preview shield| |nuget release shield|
913

1014
Python.NET is a package that gives Python programmers nearly
1115
seamless integration with the .NET Common Language Runtime (CLR) and
@@ -41,6 +45,8 @@ module:
4145
Embedding Python in .NET
4246
------------------------
4347

48+
- You must set `Runtime.PythonDLL` or `PYTHONNET_PYDLL` environment variable
49+
starting with version 3.0, otherwise you will receive `TypeInitializationException`.
4450
- All calls to python should be inside a
4551
``using (Py.GIL()) {/* Your code here */}`` block.
4652
- Import python modules using ``dynamic mod = Py.Import("mod")``, then
@@ -130,5 +136,9 @@ This project is supported by the `.NET Foundation <https://dotnetfoundation.org>
130136
:target: http://stackoverflow.com/questions/tagged/python.net
131137
.. |conda-forge version| image:: https://img.shields.io/conda/vn/conda-forge/pythonnet.svg
132138
:target: https://anaconda.org/conda-forge/pythonnet
139+
.. |nuget preview shield| image:: https://img.shields.io/nuget/vpre/pythonnet
140+
:target: https://www.nuget.org/packages/pythonnet/
141+
.. |nuget release shield| image:: https://img.shields.io/nuget/v/pythonnet
142+
:target: https://www.nuget.org/packages/pythonnet/
133143
.. |gh shield| image:: https://github.com/pythonnet/pythonnet/workflows/GitHub%20Actions/badge.svg
134144
:target: https://github.com/pythonnet/pythonnet/actions?query=branch%3Amaster

src/embed_tests/TestInterrupt.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
21
using System;
2+
using System.Diagnostics;
33
using System.Threading;
44
using System.Threading.Tasks;
55

@@ -30,34 +30,35 @@ public void Dispose()
3030
[Test]
3131
public void InterruptTest()
3232
{
33-
int runSimpleStringReturnValue = int.MinValue;
34-
ulong pythonThreadID = ulong.MinValue;
35-
Task.Factory.StartNew(() =>
33+
long pythonThreadID = 0;
34+
var asyncCall = Task.Factory.StartNew(() =>
3635
{
3736
using (Py.GIL())
3837
{
39-
pythonThreadID = PythonEngine.GetPythonThreadID();
40-
runSimpleStringReturnValue = PythonEngine.RunSimpleString(@"
38+
Interlocked.Exchange(ref pythonThreadID, (long)PythonEngine.GetPythonThreadID());
39+
return PythonEngine.RunSimpleString(@"
4140
import time
4241
4342
while True:
4443
time.sleep(0.2)");
4544
}
4645
});
4746

48-
Thread.Sleep(200);
49-
50-
Assert.AreNotEqual(ulong.MinValue, pythonThreadID);
47+
var timeout = Stopwatch.StartNew();
48+
while (Interlocked.Read(ref pythonThreadID) == 0)
49+
{
50+
Assert.Less(timeout.Elapsed, TimeSpan.FromSeconds(5), "thread ID was not assigned in time");
51+
}
5152

5253
using (Py.GIL())
5354
{
54-
int interruptReturnValue = PythonEngine.Interrupt(pythonThreadID);
55+
int interruptReturnValue = PythonEngine.Interrupt((ulong)Interlocked.Read(ref pythonThreadID));
5556
Assert.AreEqual(1, interruptReturnValue);
5657
}
5758

58-
Thread.Sleep(300);
59+
Assert.IsTrue(asyncCall.Wait(TimeSpan.FromSeconds(5)), "Async thread was not interrupted in time");
5960

60-
Assert.AreEqual(-1, runSimpleStringReturnValue);
61+
Assert.AreEqual(-1, asyncCall.Result);
6162
}
6263
}
6364
}

src/runtime/intern.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ public static void Initialize()
4242

4343
public static void Shutdown()
4444
{
45-
foreach (var ptr in _intern2strings.Keys)
45+
foreach (var entry in _intern2strings)
4646
{
47-
Runtime.XDecref(ptr);
47+
Runtime.XDecref(entry.Key);
48+
typeof(PyIdentifier).GetField(entry.Value).SetValue(null, IntPtr.Zero);
4849
}
4950
_string2interns = null;
5051
_intern2strings = null;

0 commit comments

Comments
 (0)