Closed pitrou closed 14 years ago
If I run something like: ./python -m test.regrtest -R3:2: test_threading_local
Python sometimes hangs and I have to "kill -9" it.
Running through gdb shows it gets stuck at the following point:
/home/antoine/cpython/debug/Lib/threading.py (239): wait /home/antoine/cpython/debug/Lib/threading.py (638): join /home/antoine/cpython/debug/Lib/test/test_threading_local.py (68): test_derived [snip]
That is, it hangs waiting for a thread to join().
It turns out that the __del method in _threading_local.py tries to call threading.enumerate() which itself takes the _active_limbolock. The problem is that \_del can be called at any point in time (because of the GC), including at a point where the same thread has already taken the lock. The obvious fix is to bypass enumerate().
(an alternate fix would be to use an RLock for _active_limbo_lock, but it could have unforeseen consequences, such as performance ones)
How about defining this in threading.py:
def _enumerate():
"""Internal use only: enumerate() without the lock."""
return _active.values() + _limbo.values()
And calling it from _threading_local instead of accessing _active and _limbo directly.
Good point. Here is a new patch.
Looks good to me.
typed poorly on a tiny Android phone.
On Nov 4, 2009 3:24 PM, "Antoine Pitrou" \report@bugs.python.org\ wrote:
Antoine Pitrou \pitrou@free.fr\ added the comment:
Good point. Here is a new patch.
---------- Added file: http://bugs.python.org/file15264/threading_local2.patch
___ Python tracker \< report@bugs.python.org> \<http://bugs.python...
Committed, thanks.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields: ```python assignee = None closed_at =
created_at =
labels = ['tests', 'library', 'type-crash']
title = 'test_threading_local sometimes hangs when run with -R'
updated_at =
user = 'https://github.com/pitrou'
```
bugs.python.org fields:
```python
activity =
actor = 'pitrou'
assignee = 'none'
closed = True
closed_date =
closer = 'pitrou'
components = ['Library (Lib)', 'Tests']
creation =
creator = 'pitrou'
dependencies = []
files = ['15259', '15264']
hgrepos = []
issue_num = 7264
keywords = ['patch']
message_count = 6.0
messages = ['94900', '94901', '94908', '94909', '94922', '94931']
nosy_count = 3.0
nosy_names = ['gregory.p.smith', 'pitrou', 'gps']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'crash'
url = 'https://bugs.python.org/issue7264'
versions = ['Python 2.6', 'Python 3.1', 'Python 2.7', 'Python 3.2']
```