python / python/cpython

Profilers do not work in threads

Aperta
#124,656 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

docs
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug report

Bug description:

This issue is related to, but not the same as #110770.
Running two profilers in parallel threads raises an unexpected error.
It's not clear at all that the profiler will not work in parallel.
Either this is a bug or there should be a prominent warning in the docs.

import time
from cProfile import Profile
from threading import Thread


def task_sleep() -> None:

    pr = Profile()
    pr.enable()
    time.sleep(1)
    pr.disable()


t1 = Thread(target=task_sleep)
t2 = Thread(target=task_sleep)

t1.start()
t2.start()

t1.join()
t2.join()
Exception in thread Thread-2 (task_sleep):
ValueError: Another profiling tool is already active
CPython versions tested on:

3.12

Operating systems tested on:

Windows

Linked PRs
  • gh-124671

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci il malfunzionamento con l'esempio fornito di cProfile.Profile e threading su Python 3.12, quindi esamina l'interazione tra il profiler e i thread. Esamina il PR collegato gh-124671 e determina se il risultato accettato consiste nel far funzionare i profiler paralleli senza il ValueError oppure nell'aggiungere un avviso ben visibile nella documentazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
performance
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.