[New-bugs-announce] [issue17094] sys._current_frames() reports too many/wrong stack frames

Stefan Ring report at bugs.python.org
Thu Jan 31 22:39:23 CET 2013

New submission from Stefan Ring:

After a fork, the list of thread states contains all the threads from before. It is especially unfortunate that, at least for me, it usually happens that threads created in the forked process reuse the same thread ids, and sys._current_frames will then return wrong stack frames for existing threads because the old entries occur towards the tail of the linked list and overwrite the earlier, correct ones, in _PyThread_CurrentFrames.

The attached patch is certainly not the most complete solution, but it solves my problem.

With Python 2.7.3 I get:

Exception in thread Thread-6:
Traceback (most recent call last):
  File "/usr/lib64/python2.7/threading.py", line 551, in __bootstrap_inner
  File "/usr/lib64/python2.7/threading.py", line 504, in run
    self.__target(*self.__args, **self.__kwargs)
  File "test-fork-frames.py", line 24, in do_verify
    assert frame_from_sys is real_frame

With my patch applied, it passes silently. I can reproduce this on CentOS 6.3 x86_64 as well as Fedora 18 x86_64.

components: Interpreter Core
files: current-frames-cleanup.patch
keywords: patch
messages: 181045
nosy: Ringding
priority: normal
severity: normal
status: open
title: sys._current_frames() reports too many/wrong stack frames
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file28924/current-frames-cleanup.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list