-
-
Notifications
You must be signed in to change notification settings - Fork 9
Description
I'm getting the following exception consistently from hanging_threads:
Exception in thread Thread-6:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.6/dist-packages/hanging_threads.py", line 97, in monitor
new_threads = get_current_frames()
File "/usr/local/lib/python3.6/dist-packages/hanging_threads.py", line 148, in get_current_frames
for thread_id, frame in sys._current_frames().items()
File "/usr/local/lib/python3.6/dist-packages/hanging_threads.py", line 148, in <genexpr>
for thread_id, frame in sys._current_frames().items()
KeyError: 140058396972800
When I look at that code and run the following two commands I get some odd results:
[thread_id for thread_id, frame in sys._current_frames().items()]
[t.ident for t in threading.enumerate()]
The first one is derived from the hanging_threads code using sys._current_frames()
, in that output the thread_id
for one or two of the entries is changing every time I run that command while in a debugging session. This appears to be the core of the problem, the thread_id
is invalid while building the dictionary. In the second case, using threading.enumerate()
the thread IDs remain constant.
I've tested this in Python 3.6 and 3.7.4.
I noted the following issues which reference a bug in sys._current_frames()
but seems to suggest it was fixed perhaps in 3.4/3.5 (I'm not really familiar with the bug).
- https://stackoverflow.com/questions/8110920/python-threading-sys-current-frames-vs-threading-enumerate
- https://bugs.python.org/issue17094
At this point I'm a little uncertain how to proceed, my options seem to be:
- Experiment with using
threading.enumerate()
. - Try to understand the underlying issue with
sys._current_frames()
better.
I'd love some thoughts from someone with more experience here.