Python Glossary Русский

Python 3.13+Linuxosfunction

os.timerfd_settime

os — events and timers (fd)

Arm or disarm a timerfd (start and interval in seconds). Availability: Linux.

Syntax

os.timerfd_settime(...)

initial sets the first expiration and interval the period; interval=0 makes a one-shot timer, while initial=0 disarms it. Reading the descriptor returns 8 bytes — the number of expirations since the last read, which reveals missed ticks. It returns the previous settings.

Examples

import os, time
fd = os.timerfd_create(time.CLOCK_MONOTONIC)  # → ? только Linux: дескриптор таймера
print(os.timerfd_settime(fd, initial=1.5, interval=0.5))  # → (0.0, 0.0) — прежних настроек не было; сигнал через 1.5 с, дальше каждые 0.5 с
print(int.from_bytes(os.read(fd, 8), 'little'))  # → 1 — чтение ждало первого срабатывания
print(os.timerfd_settime(fd, flags=os.TFD_TIMER_ABSTIME, initial=time.clock_gettime(time.CLOCK_MONOTONIC) + 3.0))  # → ? только Linux: примерно (0.5, 0.5) — прежние значения; новый срок задан абсолютным моментом часов
print(os.timerfd_settime(fd, initial=0.0))  # → ? только Linux: примерно (2.9, 0.0) — initial=0.0 выключает таймер

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy