The Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS
currently do not support supplying WHERE to save the
thread state via an argument. I needed that for a
project myself so I wrote the following:
#ifdef WITH_THREAD
# define MY_BEGIN_ALLOW_THREADS(st) \
{ st = PyEval_SaveThread(); }
# define MY_END_ALLOW_THREADS(st) \
{ PyEval_RestoreThread(st); st = NULL; }
#else
# define MY_BEGIN_ALLOW_THREADS(st)
# define MY_END_ALLOW_THREADS(st) { st = NULL; }
#endif
This has, of course, the drawback that whenever the
Py_BEGIN_ALLOW_THREADS macro changes I have to change mine!
Therefore, I propose that these macros (under different
names certainly) or macros that work something like
this (I can't have asymmetric { and } in them, since I
needed to retrieve the thread state somewhere else) in
the standard Python distribution.
|