Associate thread-local data/context with a faulthandler traceback

未關閉
#98,825 9 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
35/100
Issue 類型
功能
描述清晰度
需要釐清
活躍度
冷清
技術堆疊
python
領域
devtools

研究方向

從 faulthandler 模組開始,並查看連結的 Python-ideas 討論,以了解所提議的執行緒區域上下文及其限制。將函式和內容管理器範例與所要求的 traceback 輸出進行比較;要完成這項工作,需要就關聯和輸出上下文的 API 與行為達成共識。

由索引模型根據 Issue 內容生成。

描述

type-feature

Feature or enhancement

I’d like to be able to associate a thread-local string with the faulthandler module.

Pitch

The faulthandler module is invaluable for tracking down segfaults in native code, however it is really lacking the ability to add some kind of useful breadcumb to aide debugging. Imagine you are running a large-scale distributed job over tens of millions of images and a single one causes opencv to segfault reliably. This can be very difficult to track down.

It would be very useful to be able to add a string (limited by size) via the faulthandler module that is outputted along with the traceback. For example:

for image in millions_of_images():
    faulthandler.context(f'{image.id=}')
    segfaulty_function(image)

# Or maybe:
for image in millions_of_images():
    with faulthandler.context(f'{image.id=}'):
        segfaulty_function(image)

The traceback might be something like:

Fatal Python error: Segmentation fault

Current thread 0x00007fb899f39700 (most recent call first):
  .... (traceback)
Segmentation fault
Context: image_id=foo

You could of course add logging to this function to print out the image ID before you run it through segfaulty_function, but if you're running this at high volume on a huge number of machines, this becomes a bit of an overhead, and it doesn't handle multiple threads running the function well.

Previous discussion

This is lifted from the following thread on Python-ideas: https://mail.python.org/archives/list/python-ideas@python.org/message/BG36W24KEEX4YJA7CZ3PGW4ISZGVXMH6/

主要語言
Python
星號
77.2k
分支
36k
平均合併
1 天 9 小時
30 天內合併 PR
558

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

python/cpython 的其他 Issue

查看 python/cpython 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。