[Python-Dev] New thread death in test_bsddb3

"Martin v. Löwis" martin@v.loewis.de
Sat, 03 May 2003 01:39:51 +0200


Tim Peters wrote:

> Currently, no more than one at a time per thread.  The API doesn't appear to
> preclude using multiple thread states with a single thread if the right
> dances are performed.  Offhand I don't know why someone would want to, but
> people want to do a lot of silly things <wink>.

There are many good reasons; here is one scenario:

Application A calls embedded Python. It creates thread state T1 to do 
so. Python calls library L1, which releases GIL. L1 calls L2. L2 calls
back into Python. To do so, it allocates a new thread state, and 
acquires the GIL. All in one thread.

L2 has no idea that A has already allocated a thread state for this 
thread. With the new API, L2 does not need any longer to create a thread 
state. However, in older Python releases, this was necessary, so 
libraries do such things. It is unfortunate that these libraries now 
break, and I wish the new API would not be enforced so strictly yet.

> I already gave you my best guesses about those (no, yes).

I think your guess is wrong: In the past, it was often *necessary* to 
have multiple thread states allocated for a single thread. There was 
simply no other option. So it can't be that this was not allowed.

Regards,
Martin