| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Copying my comment from #1333:
Additional comments on the current state: The helper API to get the current thread id should be in the library and should use threading.get_native_id() on Python >=3.8. |
Sorry, something went wrong.
|
It would also be good if you'd just use normal commits now without force-pushing a single commit over and over, otherwise it becomes very difficult to follow your changes. We can (and will) squash this in the end. |
Sorry, something went wrong.
|
Please note that I am very unfamiliar with the codebase, so I will need more explanations from you. With regards to: |
Sorry, something went wrong.
| if (Runtime.PyVersion >= new Version(3, 8)) | ||
| { | ||
| dynamic threading = Py.Import("threading"); | ||
| return threading.get_native_id(); |
There was a problem hiding this comment.
Should get the GIL, I think.
Sorry, something went wrong.
There was a problem hiding this comment.
Isn't the user supposed to do that when calling the method, as I did in the test?
Sorry, something went wrong.
There was a problem hiding this comment.
This does not seem to be working on Ubuntu. Are you sure that this should work? Looking in CPython tests I see that get_ident is used. I don't see any benefit in adding the above lines. Should I just remove them?
Sorry, something went wrong.
|
This goes in the right direction :) Regarding 2.: Yes, that's what I meant. |
Sorry, something went wrong.
|
@filmor can this be merged now? |
Sorry, something went wrong.
| internal static extern int Py_AddPendingCall(IntPtr func, IntPtr arg); | ||
|
|
||
| [DllImport(_PythonDll, EntryPoint = "PyThreadState_SetAsyncExc", CallingConvention = CallingConvention.Cdecl)] | ||
| internal static extern int PyThreadState_SetAsyncExc37Windows(uint id, IntPtr exc); |
There was a problem hiding this comment.
Why do you need overloads with uint and int? They are basically equivalent at bit level.
Sorry, something went wrong.
There was a problem hiding this comment.
I added them because of "Strictly, the thread-id attribute is unsigned only for Python >= 3.7 and we still support 3.6" comment above. Do you want me to remove them?
Sorry, something went wrong.
There was a problem hiding this comment.
@filmor on the binary side there's no difference. The caller, if necessary, can bitcast. Any thoughts?
Sorry, something went wrong.
There was a problem hiding this comment.
I have removed the int and long declarations for now.
Sorry, something went wrong.
| public static ulong GetNativeThreadID() | ||
| { | ||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| { | ||
| return GetCurrentThreadId(); | ||
| } | ||
|
|
||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
| { | ||
| return pthread_selfLinux(); | ||
| } | ||
|
|
||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
| { | ||
| return pthread_selfOSX(); | ||
| } | ||
|
|
||
| throw new InvalidOperationException("Could not retrieve native thread ID."); | ||
| } |
There was a problem hiding this comment.
I don't think this belongs to PythonEngine. From what I read, for the test you might be able to use threading.get_ident() from Python thread module.
Sorry, something went wrong.
There was a problem hiding this comment.
get_ident is a separate thing, the IDs are not compatible with the "remote raise".
Sorry, something went wrong.
There was a problem hiding this comment.
@filmor are you sure? Documentation is very bad on this, but here's what I found:
get_ident appears to be returning PyThread_get_thread_ident
tstate->thread_id is also PyThread_get_thread_ident()
PyThreadState_SetAsyncExc finds thread by its tstate->thread_id
Sorry, something went wrong.
There was a problem hiding this comment.
Using get_ident seems to work. What would you like me to do? Modify GetNativeThreadID method or remove it completely?
Sorry, something went wrong.
There was a problem hiding this comment.
Remove it would be better.
Sorry, something went wrong.
There was a problem hiding this comment.
@lostmsu You are right. But then we should still expose threading.get_ident or PyThread_get_thread_ident, no?
Sorry, something went wrong.
There was a problem hiding this comment.
Why? The user can do what tests do now - e.g. call Py.Import("threading").Invoke("get_ident").
@gpetrou It might make sense to mention threading.get_ident() in the summary of XML doc for the Interrupt method.
Sorry, something went wrong.
There was a problem hiding this comment.
I am getting mixed signals between the two of you :) Who is the BDFL for Python.NET? I added the get_ident usage in GetNativeThreadID for now.
Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
@filmor ?
Sorry, something went wrong.
| ### Added | ||
|
|
||
| - Ability to instantiate new .NET arrays using `Array[T](dim1, dim2, ...)` syntax | ||
| - Add GetNativeThreadID and Interrupt methods in PythonEngine |
There was a problem hiding this comment.
GetNativeThreadID should be gone now
Sorry, something went wrong.
| @@ -582,28 +573,8 @@ public static void Exec(string code, IntPtr? globals = null, IntPtr? locals = nu | |||
| /// <returns>The native thread ID.</returns> | |||
| public static ulong GetNativeThreadID() | |||
There was a problem hiding this comment.
If we keep this, it should be renamed to GetPythonThreadId and doesn't this require the GIL in general?
Sorry, something went wrong.
There was a problem hiding this comment.
Can you please explain why we need GIL here and not in the Interrupt method? GIL is used for both in the tests already.
Sorry, something went wrong.
There was a problem hiding this comment.
Actually, you are right, all of the other functions in here require the GIL to be taken explicitly as well. I'm not terribly happy about this, but this should be fine then. The dynamic here should not be required, just use InvokeMethod:
var threading = ...;
return threading.InvokeMethod("get_ident");
Sorry, something went wrong.
There was a problem hiding this comment.
And renaming would still be nice, sorry for the back and forth, I misread the docs.
Sorry, something went wrong.
…ate_SetAsyncExc calls for OS and Python version
…ic methods and assert nativeThreadID value
related to pythonnet#1337
should resolve this failure: https://github.com/pythonnet/pythonnet/pull/1392/checks?check_run_id=1944113649 related to pythonnet#1337
should resolve this failure: https://github.com/pythonnet/pythonnet/pull/1392/checks?check_run_id=1944113649 related to pythonnet#1337
should resolve this failure: https://github.com/pythonnet/pythonnet/pull/1392/checks?check_run_id=1944113649 related to pythonnet#1337
should resolve this failure: https://github.com/pythonnet/pythonnet/pull/1392/checks?check_run_id=1944113649 related to #1337
| Back | FazBrowse Home | New Git URL |
What does this implement/fix? Explain your changes.
Fixes #766 by adding an Interrupt method in PythonEngine class.
Checklist
Check all those that are applicable and complete.