@@ -3780,6 +3780,174 @@ features:
3780
3780
.. versionadded :: 3.10
3781
3781
3782
3782
3783
+ .. function :: timerfd_create(clockid, flags)
3784
+
3785
+ Create and return an timerfd file descriptor. The file descriptors supports
3786
+ raw :func: `read ` with a buffer size of 8, :func: `~select.select `, :func: `~select.poll `
3787
+ and similar. See man page :manpage: `timerfd_create(2)` for more information.
3788
+
3789
+ Refer to :ref: `time-clock-id-constants ` for a list of accepted values for *clk_id *.
3790
+
3791
+ *flags * can be constructed from :const: `TFD_NONBLOCK ` and :const: `TFD_CLOEXEC `.
3792
+
3793
+ If the timerfd counter is zero and :const: `TFD_NONBLOCK ` is not
3794
+ specified, :func: `read ` blocks.
3795
+
3796
+ Example::
3797
+
3798
+ import time
3799
+ import os
3800
+
3801
+ fd = os.timerfd_create(time.CLOCK_REALTIME, 0)
3802
+
3803
+ # timer interval 0.5 second
3804
+ inteval = 0.5
3805
+
3806
+ # timer start in 1 second
3807
+ value = 1
3808
+
3809
+ # start timer
3810
+ _, _ = os.timerfd_settime(fd, 0, inteval, value)
3811
+
3812
+ try:
3813
+ while:
3814
+ # wait timerfd expired
3815
+ _ = fd.read(8)
3816
+ do_work()
3817
+ finally:
3818
+ os.close(fd)
3819
+
3820
+ Example::
3821
+
3822
+ import time
3823
+ import os
3824
+
3825
+ fd = os.timerfd_create(time.CLOCK_REALTIME, 0)
3826
+
3827
+ # timer interval 0.5 second
3828
+ inteval_ns = 10**9 // 2
3829
+
3830
+ # timer start in 1 second
3831
+ value_ns = 10**9
3832
+
3833
+ # start timer in nano second unit
3834
+ _, _ = os.timerfd_settime_ns(fd, 0, inteval_ns, value_ns)
3835
+
3836
+ try:
3837
+ while:
3838
+ # wait timerfd expired
3839
+ _ = fd.read(8)
3840
+ do_work()
3841
+ finally:
3842
+ os.close(fd)
3843
+
3844
+
3845
+ .. availability :: Linux >= 2.6.27 with glibc >= 2.8
3846
+
3847
+ .. versionadded :: 3.13
3848
+
3849
+
3850
+ .. function :: timerfd_settime(fd, flags, interval, value)
3851
+
3852
+ Start/stop timer for an timerfd file descriptor.
3853
+ See man page :manpage: `timerfd_settime(2)` for more information.
3854
+
3855
+ ``interval `` coresponds to ``it_interval `` in ``struct itimerspec `` and ``value `` coresponds to
3856
+ ``it_value `` in ``struct itimerspec ``. They are both in seconds unit and types are double.
3857
+
3858
+ ``interval `` is calculated like ``it_interval.tv_sec + it_interval.tv_nsec * 1e-9 ``,
3859
+ ``value `` is calculated like ``it_interval.tv_sec + it_interval.tv_nsec * 1e-9 `` internally.
3860
+
3861
+ .. availability :: Linux >= 2.6.27 with glibc >= 2.8
3862
+
3863
+ .. versionadded :: 3.13
3864
+
3865
+
3866
+
3867
+ .. function :: timerfd_settime_ns(fd, flags, interval_ns, value_ns)
3868
+
3869
+ Start/stop timer for an timerfd file descriptor.
3870
+ See man page :manpage: `timerfd_settime(2)` for more information.
3871
+
3872
+ ``interval_ns `` coresponds to ``it_interval `` in ``struct itimerspec `` and ``value_ns `` coresponds to
3873
+ ``it_value `` in ``struct itimerspec ``. They are both in nano second unit and types are long long.
3874
+
3875
+ ``interval `` is calculated like ``it_interval.tv_sec * 10**9 + it_interval.tv_nsec ``,
3876
+ ``value `` is calculated like ``it_interval.tv_sec * 10**9 + it_interval.tv_nsec `` internally.
3877
+
3878
+ .. availability :: Linux >= 2.6.27 with glibc >= 2.8
3879
+
3880
+ .. versionadded :: 3.13
3881
+
3882
+
3883
+ .. function :: timerfd_gettime(fd)
3884
+
3885
+ Returns a tuple ``interval `` which and ``value `` which is the time until next expiration.
3886
+ See man page :manpage: `timerfd_gettime(2)` for more information.
3887
+
3888
+ ``interval `` coresponds to ``it_interval `` in ``struct itimerspec `` and ``value `` coresponds to
3889
+ ``it_value `` in ``struct itimerspec ``. They are both in seconds unit and types are double.
3890
+
3891
+ ``interval `` is calculated like ``it_interval.tv_sec + it_interval.tv_nsec * 1e-9 ``,
3892
+ ``value `` is calculated like ``it_interval.tv_sec + it_interval.tv_nsec * 1e-9 `` internally.
3893
+
3894
+ .. availability :: Linux >= 2.6.27 with glibc >= 2.8
3895
+
3896
+ .. versionadded :: 3.13
3897
+
3898
+
3899
+ .. function :: timerfd_gettime_ns(fd)
3900
+
3901
+ Returns a tuple ``interval `` which and ``value `` which is the time until next expiration.
3902
+ See man page :manpage: `timerfd_gettime(2)` for more information.
3903
+
3904
+ ``interval `` coresponds to ``it_interval `` in ``struct itimerspec `` and ``value `` coresponds to
3905
+ ``it_value `` in ``struct itimerspec ``. They are both in nano second unit and types are long long.
3906
+
3907
+ ``interval `` is calculated like ``it_interval.tv_sec * 10**9 + it_interval.tv_nsec ``,
3908
+ ``value `` is calculated like ``it_interval.tv_sec * 10**9 + it_interval.tv_nsec `` internally.
3909
+
3910
+ .. availability :: Linux >= 2.6.27 with glibc >= 2.8
3911
+
3912
+ .. versionadded :: 3.13
3913
+
3914
+ .. data :: TFD_CLOEXEC
3915
+
3916
+ Set close-on-exec flag for new :func: `timerfd_create ` file descriptor.
3917
+
3918
+ .. availability :: Linux >= 2.6.27 with glibc >= 2.8
3919
+
3920
+ .. versionadded :: 3.13
3921
+
3922
+ .. data :: TFD_NONBLOCK
3923
+
3924
+ Set :const: `O_NONBLOCK ` status flag for new :func: `timerfd_create ` file
3925
+ descriptor.
3926
+
3927
+ .. availability :: Linux >= 2.6.27 with glibc >= 2.8
3928
+
3929
+ .. versionadded :: 3.13
3930
+
3931
+ .. data :: TFD_TIMER_ABSTIME
3932
+
3933
+ Set :const: `TFD_TIMER_ABSTIME ` flags for :func: `timerfd_settime ` or
3934
+ :func: `timerfd_settime_ns `.
3935
+
3936
+ .. availability :: Linux >= 2.6.27 with glibc >= 2.8
3937
+
3938
+ .. versionadded :: 3.13
3939
+
3940
+
3941
+ .. data :: TFD_TIMER_CANCEL_ON_SET
3942
+
3943
+ Set :const: `TFD_TIMER_CANCEL_ON_SET ` flags for :func: `timerfd_settime ` or
3944
+ :func: `timerfd_settime_ns `.
3945
+
3946
+ .. availability :: Linux >= 2.6.27 with glibc >= 2.8
3947
+
3948
+ .. versionadded :: 3.13
3949
+
3950
+
3783
3951
Linux extended attributes
3784
3952
~~~~~~~~~~~~~~~~~~~~~~~~~
3785
3953
0 commit comments