Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

spin loop in client/threadedclient.py causes cpu use in idle processes

Aperta
#142 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
45/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
networking

Direzione di ricerca

Open client/threadedclient.py and read WebSocketClient.run_forever(), then review the history reference to issue #109 for the timeout rationale. Done means the existing timeout and SIGINT behavior are clearly documented in a comment without changing the loop.

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

Descrizione

bug

In client.threadedclient, WebSocketClient has a method run_forever(). The body of the code is:

    while not self.terminated:
        self._th.join(timeout=0.1)

top was showing bunches of processes that weren't doing anything, which I eventually traced to this spin loop. Of course, my first thought was WTF? because there is no apparent need for a timeout here. I managed to trace the code through the github history and found a reference to issue #109

I suggest a comment something like this in this function:

# signals and threads are not friends in python.  Without the timeout, you can't
# interrupt this function with SIGINT.  The timeout ensures that we return to the
# main thread periodically, so a pending SIGINT can be processed.  If this causes
# unreasonable CPU usage in your application, just override this method to not
# have a timeout, and don't try to interrupt it with SIGINT.

It is not clear to me that this is a problem for most users, but it was for me. I first noticed because the fans in my computer were speeding up even though my application wasn't doing anything. (I have lots of processes on standby.)

Lingua principale
Python
Stelle
1.1k
Fork
285
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

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.

Altre issue di Lawouach/WebSocket-for-Python

Tutte le issue di Lawouach/WebSocket-for-Python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.