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

Skip to content

Commit c455ee4

Browse files
committed
Rename to GetPythonThreadID
1 parent f077caf commit c455ee4

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1111

1212
- Ability to instantiate new .NET arrays using `Array[T](dim1, dim2, ...)` syntax
1313
- Python operator method will call C# operator method for supported binary and unary operators ([#1324][p1324]).
14-
- Add GetNativeThreadID and Interrupt methods in PythonEngine
14+
- Add GetPythonThreadID and Interrupt methods in PythonEngine
1515

1616
### Changed
1717
- Drop support for Python 2, 3.4, and 3.5

src/embed_tests/TestInterrupt.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public void Dispose()
3131
public void InterruptTest()
3232
{
3333
int runSimpleStringReturnValue = int.MinValue;
34-
ulong nativeThreadID = ulong.MinValue;
34+
ulong pythonThreadID = ulong.MinValue;
3535
Task.Factory.StartNew(() =>
3636
{
3737
using (Py.GIL())
3838
{
39-
nativeThreadID = PythonEngine.GetNativeThreadID();
39+
pythonThreadID = PythonEngine.GetPythonThreadID();
4040
runSimpleStringReturnValue = PythonEngine.RunSimpleString(@"
4141
import time
4242
@@ -47,11 +47,11 @@ import time
4747

4848
Thread.Sleep(200);
4949

50-
Assert.AreNotEqual(ulong.MinValue, nativeThreadID);
50+
Assert.AreNotEqual(ulong.MinValue, pythonThreadID);
5151

5252
using (Py.GIL())
5353
{
54-
int interruptReturnValue = PythonEngine.Interrupt(nativeThreadID);
54+
int interruptReturnValue = PythonEngine.Interrupt(pythonThreadID);
5555
Assert.AreEqual(1, interruptReturnValue);
5656
}
5757

src/runtime/pythonengine.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -568,28 +568,28 @@ public static void Exec(string code, IntPtr? globals = null, IntPtr? locals = nu
568568
}
569569

570570
/// <summary>
571-
/// Gets the native thread ID.
571+
/// Gets the Python thread ID.
572572
/// </summary>
573-
/// <returns>The native thread ID.</returns>
574-
public static ulong GetNativeThreadID()
573+
/// <returns>The Python thread ID.</returns>
574+
public static ulong GetPythonThreadID()
575575
{
576-
dynamic threading = Py.Import("threading");
577-
return threading.get_ident();
576+
var threading = Py.Import("threading");
577+
return threading.InvokeMethod("get_ident");
578578
}
579579

580580
/// <summary>
581581
/// Interrupts the execution of a thread.
582582
/// </summary>
583-
/// <param name="nativeThreadID">The native thread ID.</param>
583+
/// <param name="pythonThreadID">The Python thread ID.</param>
584584
/// <returns>The number of thread states modified; this is normally one, but will be zero if the thread id isn’t found.</returns>
585-
public static int Interrupt(ulong nativeThreadID)
585+
public static int Interrupt(ulong pythonThreadID)
586586
{
587587
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
588588
{
589-
return Runtime.PyThreadState_SetAsyncExcLLP64((uint)nativeThreadID, Exceptions.KeyboardInterrupt);
589+
return Runtime.PyThreadState_SetAsyncExcLLP64((uint)pythonThreadID, Exceptions.KeyboardInterrupt);
590590
}
591591

592-
return Runtime.PyThreadState_SetAsyncExcLP64(nativeThreadID, Exceptions.KeyboardInterrupt);
592+
return Runtime.PyThreadState_SetAsyncExcLP64(pythonThreadID, Exceptions.KeyboardInterrupt);
593593
}
594594

595595
/// <summary>

0 commit comments

Comments
 (0)