Python Glossary Русский

Python 3.10+Linuxosfunction

os.eventfd_read

os — events and timers (fd)

Read (and reset) the counter value from an eventfd. Availability: Linux.

Syntax

os.eventfd_read(...)

If the counter is zero it blocks until the first write; with EFD_NONBLOCK it raises BlockingIOError instead. It returns the accumulated sum: writes of 3 and 4 read back as 7. Reading and resetting happen atomically.

Examples

import os
fd = os.eventfd(0, os.EFD_NONBLOCK)   # → ? только Linux: счётчик 0, чтение не будет блокировать
os.eventfd_write(fd, 2)   # → ? только Linux: счётчик 0 → 2
os.eventfd_write(fd, 3)   # → ? только Linux: счётчик 2 → 5
print(os.eventfd_read(fd))   # → 5 — записи суммируются до первого чтения
print(os.eventfd_read(fd))   # → BlockingIOError, счётчик пуст; без EFD_NONBLOCK вызов заблокировался бы навсегда

See also

Open in the full glossarydocs.python.orgReport an inaccuracy