Python Glossary Русский

Python 3.13+Linuxosfunction

os.timerfd_create

os — events and timers (fd)

Create a timer file descriptor whose expirations are readable as events (3.13+). Availability: Linux.

Syntax

os.timerfd_create(...)

A timer whose expirations are read as data from a descriptor, so it can be waited on alongside sockets in one select. The clock is an argument: time.CLOCK_MONOTONIC does not jump when the system time changes, unlike CLOCK_REALTIME. The timer still has to be armed with timerfd_settime.

Examples

import os, time
fd = os.timerfd_create(time.CLOCK_MONOTONIC)  # → ? только Linux: файловый дескриптор таймера, например 3
os.timerfd_settime(fd, initial=1.0)  # → ? только Linux: одноразовый сигнал через 1 секунду
print(int.from_bytes(os.read(fd, 8), 'little'))  # → 1 — чтение блокировалось до срабатывания таймера
os.close(fd)  # → ? только Linux: таймер остановлен вместе с закрытием дескриптора
nb = os.timerfd_create(time.CLOCK_REALTIME, flags=os.TFD_NONBLOCK)  # → ? только Linux: чтение до срабатывания даст BlockingIOError, а не блокировку

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy