Python Glossary Русский

Python 3.10+Linuxosfunction

os.eventfd_write

os — events and timers (fd)

Add a value to an eventfd counter. Availability: Linux.

Syntax

os.eventfd_write(...)

It adds a number to the counter and wakes waiting readers. The value must be non-negative (0 is allowed and changes nothing) and below 2**64 - 1; on overflow the write blocks, or raises BlockingIOError in non-blocking mode.

Examples

import os
fd = os.eventfd(0, os.EFD_NONBLOCK)   # → ? только Linux: счётчик 0
os.eventfd_write(fd, 1)   # → ? только Linux: счётчик 0 → 1, ожидающий читатель просыпается
os.eventfd_write(fd, 4)   # → ? только Linux: счётчик 1 → 5, значения складываются, а не заменяют друг друга
print(os.eventfd_read(fd))   # → 5
os.eventfd_write(fd, -1)   # → ValueError: счётчик беззнаковый, отрицательное значение в него не помещается

See also

Open in the full glossarydocs.python.orgReport an inaccuracy