logging: Logger.setLevel() and logging.disable() are O(number of loggers)
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 38/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- python
- Bereich
- backend, performance
Rechercherichtung
Start with Manager._clear_cache() and Logger.isEnabledFor() in CPython’s logging implementation, then inspect the logging tests that cover cache invalidation. The issue includes a benchmark reproducing quadratic behavior across thousands of loggers. Done means cache clearing scales with loggers that have cached values while preserving correct isEnabledFor() results after level changes.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Bug report
Every Logger.setLevel() and logging.disable() call goes through Manager._clear_cache(), which walks the whole loggerDict and clears each logger's isEnabledFor cache, even the ones that never cached anything. So setting the level on N loggers one by one is quadratic. That shows up in apps or test suites with thousands of loggers (one per module/plugin/connection) that get configured individually.
import logging, time
for n in (1000, 2000, 4000, 8000):
logging.root.manager.loggerDict.clear()
loggers = [logging.getLogger(f"app.mod{i}") for i in range(n)]
for lg in loggers:
lg.isEnabledFor(logging.DEBUG)
t = time.perf_counter()
for lg in loggers:
lg.setLevel(logging.INFO)
print(f"{n:5d} loggers: {time.perf_counter() - t:.3f} s")
On 3.14.7 this gives about 0.23 s at 2000 loggers, 0.89 s at 4000 and 4.4 s at 8000 (each doubling is about 4x).
A fix is to have the manager remember which loggers actually have something in their cache (a WeakSet filled on the isEnabledFor cache-miss path, which already holds the lock) and only clear those. The cache-hit path doesn't change. I have a patch ready and can open a PR.
CPython versions tested on:
3.14, CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-160937
- Vorherrschende Sprache
- Python
- Sterne
- 77.8k
- Forks
- 37.7k
- Ø Merge
- 15 Std. 24 Min.
- Gemergte PRs (30 T.)
- 728
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python/cpython
-
What's New in 3.12 credits the unstable C API tier to PEP 697 instead of PEP 689Evtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offendocs
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 82/100
python/cpython#161078 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
OS-windows type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
docs
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
python/cpython#161007 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Null dereferencing of a pointer in initconfig.cEvtl. vergeben @lazerg hat das vor 3 Tagen übernommen. Offeninterpreter-core topic-C-API type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
python/cpython#160962 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
tests topic-profiling type-bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
python/cpython#160881 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
pytest-dev/pyfakefs#1367 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
IFEvalG exclude_word_harder misses the keyword next to punctuation, at the start or end of the text, and in other letter caseEvtl. vergeben @damienen hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
allenai/open-instruct#2151 ·
Maintainer antworten meist innerhalb von 1 Tag
-
feat(plan): support convertorLabels and convertorAffinity in Plan resourceEvtl. vergeben @AmenB hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
RedHatQE/openshift-python-wrapper#2849 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Maintainer antworten meist innerhalb von 25 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
libnativeapi/nativeapi#21 ·