@@ -3280,7 +3280,8 @@ features:
3280
3280
3281
3281
Create and return an event file descriptor. The file descriptors supports
3282
3282
raw :func: `read ` and :func: `write ` with a buffer size of 8,
3283
- :func: `~select.select `, :func: `~select.poll ` and similar. By default, the
3283
+ :func: `~select.select `, :func: `~select.poll ` and similar. See man page
3284
+ :manpage: `eventfd(2)` for more information. By default, the
3284
3285
new file descriptor is :ref: `non-inheritable <fd_inheritance >`.
3285
3286
3286
3287
*initval * is the initial value of the event counter. The initial value
@@ -3298,12 +3299,30 @@ features:
3298
3299
non-zero, :func: `eventfd_read ` returns the current event counter value and
3299
3300
resets the counter to zero.
3300
3301
3301
- If the event counter is zero, :func: `eventfd_read ` blocks.
3302
+ If the event counter is zero and :const: `EFD_NONBLOCK ` is not
3303
+ specified, :func: `eventfd_read ` blocks.
3302
3304
3303
3305
:func: `eventfd_write ` increments the event counter. Write blocks if the
3304
3306
write operation would increment the counter to a value larger than
3305
3307
2\ :sup: `64`\ -\ 2.
3306
3308
3309
+ Example::
3310
+
3311
+ import os
3312
+
3313
+ # semaphore with start value '1'
3314
+ fd = os.eventfd(1, os.EFD_SEMAPHORE | os.EFC_CLOEXEC)
3315
+ try:
3316
+ # acquire semaphore
3317
+ v = os.eventfd_read(fd)
3318
+ try:
3319
+ do_work()
3320
+ finally:
3321
+ # release semaphore
3322
+ os.eventfd_write(fd, v)
3323
+ finally:
3324
+ os.close(fd)
3325
+
3307
3326
.. availability :: Linux 2.6.27 or newer with glibc 2.8 or newer.
3308
3327
3309
3328
.. versionadded :: 3.10
0 commit comments