[ python-Bugs-926910 ] Overenthusiastic check in Swap?

SourceForge.net noreply at sourceforge.net
Tue Aug 21 03:18:53 CEST 2007


Bugs item #926910, was opened at 2004-04-01 05:34
Message generated for change (Comment added) made by mhammond
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=926910&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Threads
Group: None
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Private: No
Submitted By: benson margulies (benson_basis)
Assigned to: Mark Hammond (mhammond)
Summary: Overenthusiastic check in Swap?

Initial Comment:
When Py_DEBUG is turned on, PyThreadState_Swap 
calls in a fatal error if the two different thread states 
are ever used for a thread.

I submit that this is not a good check. The 
documentation encourages us to write code that 
creates and destroys thread states as C threads come 
and go. Why can't a single C thread make a thread 
state, release it, and then make another one later?

One particular usage pattern:

We have an API that initializes embedded python. Then 
we have another API where the callers are allowed to be 
in any C thread. The second API has no easy way to tell 
if a thread used for it happens to be the same thread 
that made the initialization call. As the code is written 
now, any code running on the 'main thread' is required 
to fish out the build-in main-thread thread state.


----------------------------------------------------------------------

>Comment By: Mark Hammond (mhammond)
Date: 2007-08-21 11:18

Message:
Logged In: YES 
user_id=14198
Originator: NO

The docs probably could be improved, but for now, this bug as reported is
not going to be fixed.

----------------------------------------------------------------------

Comment By: benson margulies (benson_basis)
Date: 2004-06-08 00:20

Message:
Logged In: YES 
user_id=876734

Somehow, the path I took through the documentation failed 
to rub my nose in this. It would be good if the language from 
the original PEP was applied to the APIs that I coded to to 
warn people to use these other APIs instead.


----------------------------------------------------------------------

Comment By: Mark Hammond (mhammond)
Date: 2004-06-07 17:22

Message:
Logged In: YES 
user_id=14198

That check should not fail if you use the PyGILState APIs -
it manages all of this for you.  The PyGILState functions
were added to handle exactly what you describe as your use
case - is there any reason you can't use them?

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-06-07 15:15

Message:
Logged In: YES 
user_id=80475

Mark, I believe this is your code.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=926910&group_id=5470


More information about the Python-bugs-list mailing list