python / python/cpython

Associate thread-local data/context with a faulthandler traceback

Offen
#98,825 9 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

type-feature
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
36k
Ø Merge
1 T. 9 Std.
Gemergte PRs (30 T.)
558

Beschreibung

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/

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem faulthandler-Modul und prüfe die verlinkte Python-ideas-Diskussion, um den vorgeschlagenen thread-lokalen Kontext und seine Einschränkungen zu verstehen. Vergleiche die Beispiele für Funktionen und Context Manager mit der angeforderten Traceback-Ausgabe; für den Abschluss wären eine vereinbarte API und ein vereinbartes Verhalten für das Zuordnen und Ausgeben des Kontexts erforderlich.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
devtools
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Ruhig
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.