python / python/cpython

Allow sleeping until an absolute time

Aperta
#101,558 7 commenti 8 reazioni 1 assegnatario Vedi su GitHub

@abalkin ci sta già lavorando.

Dal 6/2/2023.

stdlib type-feature
Lingua principale
Python
Stelle
77.2k
Fork
36k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

I propose a version of time.sleep() that allows for the specification of absolute times.

Python 3.11 added the use of clock_nanosleep in time.sleep() (#28111), and both it and Windows' SetWaitableTimerEx allow for the specification of absolute times. This can be useful for writing simple loops that trigger at an interval that is tied to wall-clock time, which has many applications: triggering taking of measurements, pictures, checking status, sending messages, ...

With time.sleep(), one has to emulate this by saying time.sleep(deadline - time.time()), which pysleep then calculates back into an absolute time internally, which adds inaccuracy.

I will be submitting a pull request shortly that modifies pysleep to give it an "absolute" argument and adds a time.sleep_until() function.

Linked PRs
  • gh-101559

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.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.