Using SaveThread and RestoreThread with callbacks

Aahz aahz at pythoncraft.com
Fri Oct 11 11:42:26 EDT 2002


In article <b55100a.0210102331.3fb1eb03 at posting.google.com>,
Adam Rutkowski <adam at cardaccess.com.au> wrote:
>
>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)

Don't Do That.  Just use the macros Py_BEGIN_ALLOW_THREADS and
Py_END_ALLOW_THREADS.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Project Vote Smart: http://www.vote-smart.org/



More information about the Python-list mailing list