You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need access to the PyThreadState_GetDict cpython call.
I have embedded Python.Net in my app but since I have multiple threads (tasks) running scripts and calling back into C#, I require a way to store my thread context into the current Python thread.
To to this I imported PyThreadState_GetDict myself (worked fine), but I also needed the other low level cpython calls that are set as internal in the Python.Runtime class.
So here would be the new member exposed by Python.Runtime (or somewhere)
public PyDict GetThreadStateDict()
{
IntPtr dict = Runtime.PyThreadState_GetDict();
Runtime.XIncref(dict); // borrowed ref
return new PyDict(dict);
}
That is, unless there's a better way to keep track of what original thread is calling back into the app.
Maybe the Python Thread Specific Storage (TSS) API would be better?
ok, you're right, I just implemented ThreadLocal and it works better & faster in one line.
I'm porting from c++, a c++ object was stored in the python thread state dict in the older app. I just basically copied the same implementation.
So no need for Python.Runtime internal access either.
Thanks for taking the time and pointing out something that should have been obvious to me...
Activity
lostmsu commentedon Sep 2, 2020
@quickwire is there any reason you can not use .NET
ThreadLocal<T>or any similar class from Python standard library?bmiller-pm commentedon Sep 3, 2020
ok, you're right, I just implemented ThreadLocal and it works better & faster in one line.
I'm porting from c++, a c++ object was stored in the python thread state dict in the older app. I just basically copied the same implementation.
So no need for Python.Runtime internal access either.
Thanks for taking the time and pointing out something that should have been obvious to me...