| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,15 +10,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. | |||
| 10 | 10 | ### Added | |
| 11 | 11 | ||
| 12 | 12 | - Ability to instantiate new .NET arrays using `Array[T](dim1, dim2, ...)` syntax | |
| 13 | - <<<<<<< HEAD | ||
| 14 | - <<<<<<< HEAD | ||
| 15 | 13 | - Python operator method will call C# operator method for supported binary and unary operators ([#1324][p1324]). | |
| 16 | - ======= | ||
| 17 | - - Add Interrupt method in PythonEngine | ||
| 18 | - >>>>>>> Add Interrupt method in PythonEngine | ||
| 19 | - ======= | ||
| 20 | 14 | - Add GetNativeThreadID and Interrupt methods in PythonEngine | |
| 21 | - >>>>>>> Add GetNativeThreadID method in PythonEngine and different PyThreadState_SetAsyncExc calls for OS and Python version | ||
| 22 | 15 | ||
| 23 | 16 | ### Changed | |
| 24 | 17 | - Drop support for Python 2, 3.4, and 3.5 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,7 +31,7 @@ public void Dispose() | |||
| 31 | 31 | public void InterruptTest() | |
| 32 | 32 | { | |
| 33 | 33 | int runSimpleStringReturnValue = int.MinValue; | |
| 34 | - uint nativeThreadID = uint.MinValue; | ||
| 34 | + ulong nativeThreadID = ulong.MinValue; | ||
| 35 | 35 | Task.Factory.StartNew(() => | |
| 36 | 36 | { | |
| 37 | 37 | using (Py.GIL()) | |
@@ -47,6 +47,8 @@ import time | |||
| 47 | 47 | ||
| 48 | 48 | Thread.Sleep(200); | |
| 49 | 49 | ||
| 50 | + Assert.AreNotEqual(ulong.MinValue, nativeThreadID); | ||
| 51 | + | ||
| 50 | 52 | using (Py.GIL()) | |
| 51 | 53 | { | |
| 52 | 54 | int interruptReturnValue = PythonEngine.Interrupt(nativeThreadID); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,15 +12,6 @@ namespace Python.Runtime | |||
| 12 | 12 | /// </summary> | |
| 13 | 13 | public class PythonEngine : IDisposable | |
| 14 | 14 | { | |
| 15 | - [DllImport("Kernel32", EntryPoint = "GetCurrentThreadId", ExactSpelling = true)] | ||
| 16 | - private static extern uint GetCurrentThreadId(); | ||
| 17 | - | ||
| 18 | - [DllImport("libc", EntryPoint = "pthread_self")] | ||
| 19 | - private static extern UIntPtr pthread_selfLinux(); | ||
| 20 | - | ||
| 21 | - [DllImport("pthread", EntryPoint = "pthread_self", CallingConvention = CallingConvention.Cdecl)] | ||
| 22 | - private static extern uint pthread_selfOSX(); | ||
| 23 | - | ||
| 24 | 15 | public static ShutdownMode ShutdownMode | |
| 25 | 16 | { | |
| 26 | 17 | get => Runtime.ShutdownMode; | |
@@ -580,55 +571,25 @@ public static void Exec(string code, IntPtr? globals = null, IntPtr? locals = nu | |||
| 580 | 571 | /// Gets the native thread ID. | |
| 581 | 572 | /// </summary> | |
| 582 | 573 | /// <returns>The native thread ID.</returns> | |
| 583 | - public static uint GetNativeThreadID() | ||
| 574 | + public static ulong GetNativeThreadID() | ||
| 584 | 575 | { | |
| 585 | - if (Runtime.PyVersion >= new Version(3, 8)) | ||
| 586 | - { | ||
| 587 | - dynamic threading = Py.Import("threading"); | ||
| 588 | - return threading.get_native_id(); | ||
| 589 | - } | ||
| 590 | - | ||
| 591 | - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| 592 | - { | ||
| 593 | - return GetCurrentThreadId(); | ||
| 594 | - } | ||
| 595 | - | ||
| 596 | - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
| 597 | - { | ||
| 598 | - return pthread_selfLinux().ToUInt32(); | ||
| 599 | - } | ||
| 600 | - | ||
| 601 | - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
| 602 | - { | ||
| 603 | - return pthread_selfOSX(); | ||
| 604 | - } | ||
| 605 | - | ||
| 606 | - throw new InvalidOperationException("Could not retrieve native thread ID."); | ||
| 576 | + dynamic threading = Py.Import("threading"); | ||
| 577 | + return threading.get_ident(); | ||
| 607 | 578 | } | |
| 608 | 579 | ||
| 609 | 580 | /// <summary> | |
| 610 | 581 | /// Interrupts the execution of a thread. | |
| 611 | 582 | /// </summary> | |
| 612 | 583 | /// <param name="nativeThreadID">The native thread ID.</param> | |
| 613 | 584 | /// <returns>The number of thread states modified; this is normally one, but will be zero if the thread id isn’t found.</returns> | |
| 614 | - public static int Interrupt(uint nativeThreadID) | ||
| 585 | + public static int Interrupt(ulong nativeThreadID) | ||
| 615 | 586 | { | |
| 616 | - if (Runtime.PyVersion >= new Version(3, 7)) | ||
| 617 | - { | ||
| 618 | - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| 619 | - { | ||
| 620 | - return Runtime.PyThreadState_SetAsyncExc37Windows(nativeThreadID, Exceptions.KeyboardInterrupt); | ||
| 621 | - } | ||
| 622 | - | ||
| 623 | - return Runtime.PyThreadState_SetAsyncExc37NonWindows(new UIntPtr(nativeThreadID), Exceptions.KeyboardInterrupt); | ||
| 624 | - } | ||
| 625 | - | ||
| 626 | 587 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | |
| 627 | 588 | { | |
| 628 | - return Runtime.PyThreadState_SetAsyncExc36Windows((int)nativeThreadID, Exceptions.KeyboardInterrupt); | ||
| 589 | + return Runtime.PyThreadState_SetAsyncExcLLP64((uint)nativeThreadID, Exceptions.KeyboardInterrupt); | ||
| 629 | 590 | } | |
| 630 | 591 | ||
| 631 | - return Runtime.PyThreadState_SetAsyncExc36NonWindows(new IntPtr(nativeThreadID), Exceptions.KeyboardInterrupt); | ||
| 592 | + return Runtime.PyThreadState_SetAsyncExcLP64(nativeThreadID, Exceptions.KeyboardInterrupt); | ||
| 632 | 593 | } | |
| 633 | 594 | ||
| 634 | 595 | /// <summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2147,16 +2147,10 @@ internal static void Py_CLEAR(ref IntPtr ob) | |||
| 2147 | 2147 | internal static extern int Py_AddPendingCall(IntPtr func, IntPtr arg); | |
| 2148 | 2148 | ||
| 2149 | 2149 | [DllImport(_PythonDll, EntryPoint = "PyThreadState_SetAsyncExc", CallingConvention = CallingConvention.Cdecl)] | |
| 2150 | - internal static extern int PyThreadState_SetAsyncExc37Windows(uint id, IntPtr exc); | ||
| 2150 | + internal static extern int PyThreadState_SetAsyncExcLLP64(uint id, IntPtr exc); | ||
| 2151 | 2151 | ||
| 2152 | 2152 | [DllImport(_PythonDll, EntryPoint = "PyThreadState_SetAsyncExc", CallingConvention = CallingConvention.Cdecl)] | |
| 2153 | - internal static extern int PyThreadState_SetAsyncExc36Windows(int id, IntPtr exc); | ||
| 2154 | - | ||
| 2155 | - [DllImport(_PythonDll, EntryPoint = "PyThreadState_SetAsyncExc", CallingConvention = CallingConvention.Cdecl)] | ||
| 2156 | - internal static extern int PyThreadState_SetAsyncExc37NonWindows(UIntPtr id, IntPtr exc); | ||
| 2157 | - | ||
| 2158 | - [DllImport(_PythonDll, EntryPoint = "PyThreadState_SetAsyncExc", CallingConvention = CallingConvention.Cdecl)] | ||
| 2159 | - internal static extern int PyThreadState_SetAsyncExc36NonWindows(IntPtr id, IntPtr exc); | ||
| 2153 | + internal static extern int PyThreadState_SetAsyncExcLP64(ulong id, IntPtr exc); | ||
| 2160 | 2154 | ||
| 2161 | 2155 | [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | |
| 2162 | 2156 | internal static extern int Py_MakePendingCalls(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments