This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Update to the BEGIN_ALLOW_THREADS macros
Type: enhancement Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, dubnerm, msjogren, nnorwitz
Priority: low Keywords:

Created on 2001-07-23 12:34 by msjogren, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Messages (4)
msg53170 - (view) Author: Martin Sjögren (msjogren) Date: 2001-07-23 12:34
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.
msg53171 - (view) Author: Michael Dubner (dubnerm) Date: 2003-01-18 05:16
Logged In: YES 
user_id=39274

I think that current Py_BEGIN/END_ALLOW_THREADS macroses
model (with block) is choosen to enforce compile-time
pairwise check. Isn't it?
msg53172 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-05-13 00:08
Logged In: YES 
user_id=357491

Couldn't you cheat and access the _save variable that 
Py_BEGIN_ALLOW_THREADS creates?  And does PEP 311 help solve your 
usage need at all?
msg53173 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2007-03-16 05:27
As Brett says, you can use the _save variable.  Since no one else has requested this feature it doesn't seem worth it to change.
History
Date User Action Args
2022-04-10 16:04:13adminsetgithub: 34815
2001-07-23 12:34:53msjogrencreate