On Nov 6, 8:25 pm, snd...(a)gmail.com wrote:
> i naively created execution context:
> PyObject *execcontext = PyDict_New();
> stuffed a handle in it:
> PyObject *ih = PyCObject_FromVoidPtr(handle, NULL);
> int st= PyDict_SetItemString(res, "interp", ih);
>
> and later on in a function for a module that i defined
> expected to extract that handle:
> PyObject *dict = PyEval_GetGlobals(); // or GetLocals
> depending on where
> // execcontext …
[View More]ended up in PyEval_EvalCode
> PyObject *co = PyDict_GetItemString(dict, "interp");
> assert(PyCObject_Check(co));
> but i get null co either way and the dict does not match execcontext
> that is passed into PyEval_EvalCode.
>
> any ideas how to fix this?
in other words: is there a scope more global than a module scope?
something that won't change for a given PyEval_EvalCode or a similar call.
i stuffed my CObject into __main__ but in case of multiple threads or
nested PyEval_EvalCode i'd have a problem with this approach.
i somehow just need to get to the pointer to the same dictionary that
i passed to PyEval_EvalCode for global scope to retrieve my handle
in a method of a new python type defined in C space.
thank you
[View Less]
I see some api published for marshal module:
http://www.python.org/dev/doc/maint24/api/marshalling-utils.html
but per latest discussion on comp.lang.python
people were suggesting to use pickle.
If i pass the marshalled string to a machine running python on
a machine with a different byte order, would it unmarshall correctly?
Hello,
I create lots of threads that run a script and I have a problem when a
thread is created with the same threadId that existed before.
When a new thread is started I use this code to enter the interpreter:
// create a thread state object for this thread
PyEval_AcquireLock();
threadState = PyThreadState_New(mainInterpreterState);
PyThreadState_Swap(threadState);
and when the thread finishes:
PyThreadState_Swap(NULL);
PyThreadState_Clear(info);
// delete my thread state object
…
[View More]PyThreadState_Delete(info);
PyEval_ReleaseLock();
Everything works smoothly until a thread id is re-used.
I've been testing what is happening and the problem is that
PyGILState_GetThisThreadState() returns a PyThreadState for the reused
thread id.
I changed my code to call PyGILState_GetThisThreadState() before creating
the PyThreadState. But if I try to use the returned PyThreadState (that
shouldn't exist because I've already deleted) I got an error when trying to
access the interpreter dictionary.
The workaround that I found is to keep all PyThreadState structures without
calling PyThreadState_Clear / PyThreadState_Delete. When a new thread is
created I call PyGILState_GetThisThreadState(). If it returns something I
reuse the structure.
In this way, my code works.
Thanks,
Pablo Yabo
--
http://www.nektra.com
[View Less]