Using SaveThread and RestoreThread with callbacks

Adam Rutkowski adam at cardaccess.com.au
Fri Oct 11 09:31:58 CEST 2002


Hi all! I've got a problem with some code that I'm trying to resolve,
and to do so, there's a question that I'm trying to find the answer
to, so I'm hoping someone may be able to help.

I've got some Python code calling a C function, which performs a
PyEval_SaveThread(), does some stuff, then calls a
PyEvalRestoreThread(). The problem is, part of the stuff it does is
execute a Python callback function. To do this, it performs a
PyEvalRestoreThread(), does the callback, then does a
PyEval_SaveThread(). So the code looks something like this:

x = PyEval_SaveThread()
     C stuff...
   PyEvalRestoreThread(x)
     Callback()
   x = PyEval_SaveThread()
     C stuff...
PyEvalRestoreThread(x)


The question is, is this the way I should be doing things? I don't
quite understand what thread state information is being
saved/restored, so I don't whether it's possible for code to alter the
thread state in such a way that restoring to a saved thread state will
cause problems.

Any help would really be appreciated.

Adam Rutkowski



More information about the Python-list mailing list