ID EN
OS

eventfd

Python 3.11

Create and return an event file descriptor. The file descriptors supports raw read() and write() with a buffer size of 8, select(), poll() and similar. See man page eventfd(2) for more information. By default, the new file descriptor is non-inheritable.

Syntax

PYTHON
os.eventfd(initval[, flags=os.EFD_CLOEXEC])

Examples

Example 1
PYTHON
import os

 semaphore with start value '1'
fd = os.eventfd(1, os.EFD_SEMAPHORE | os.EFC_CLOEXEC)
try:
     acquire semaphore
    v = os.eventfd_read(fd)
    try:
        do_work()
    finally:
         release semaphore
        os.eventfd_write(fd, v)
finally:
    os.close(fd)

See Also

read() write() select() poll() non-inheritable EFD_CLOEXEC EFD_NONBLOCK EFD_SEMAPHORE