-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-108277: Add wrapper for timerfd_create, timerfd_settime, and timerfd_gettime to os module #108382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-108277: Add wrapper for timerfd_create, timerfd_settime, and timerfd_gettime to os module #108382
Changes from 1 commit
0f8aaf5
208fd58
37f70cd
6f63cf7
0f47920
03f319d
b8e39f2
44b3ac7
a549684
5e33c3e
7da832d
d0905d9
0eed49a
fd718d9
4b89526
75614a1
458ae17
1f1d22e
dda4c31
909c50a
c53a84d
7e306f5
af8a9f2
74cdc6c
fc585b8
3879a71
04aa70b
efe3d1d
132ef60
c6d9fb0
f7af17c
94f248d
3366d58
d57cfbe
4b13a5c
94839ac
4c783e8
b65fd4c
bdbeef0
e1abd07
50e17c9
d8043a2
8024c9e
6e251af
914c7d0
cd6b32b
d411858
02dac34
a819904
f812cbe
6db493f
fcf3efc
44bc810
f742b8f
cbbc97b
977f574
f86afb2
0491421
de4477d
3915eea
4ae90da
e380aef
e7d967d
c7e8593
1d4d3b5
6565fea
f0623b9
64f1571
e8c8b60
74c12d1
8051b9b
e9d4753
ed6d3b2
ef0449a
1faf245
22315c8
cc63a06
ec8f2ec
1319814
7410a7c
aed85ab
1138cf9
95025c5
d0ed353
9309e4b
3548656
8a8b706
e1d993f
c2b8ddf
bd23f53
b97d694
c3f1904
3b8e3dc
2db35e3
180830f
ac7ee82
9cec110
86f5a8e
ce53a4f
814cc29
a48c3a6
da453b8
3f9bd62
69b9cfa
b2f507a
d5e782d
f83058a
49e6981
765e584
3d55e2e
0011278
6080d32
32ba03f
789b909
3a66967
817933e
c090ada
0e9f5b3
ae6b885
79b74b0
fa00db9
20a0674
908e3dc
171c71a
8fb3fdf
7c470fb
189843a
2741533
3d527da
2fd8804
5aba21f
dadcf60
6a77a1b
9d78861
24ae1d9
552638f
8fde913
f417c7c
4460475
ae8c3da
4aeb95e
f06e352
b8e3b23
ed34c2c
3fc0a5a
4783a13
7919b09
b2ad6c8
da47484
3661045
6d1e7c7
69897fc
5c78372
62782bc
4ff50a3
dc15134
92b7a32
f4b9865
e0f5d7c
6f1d788
64331c4
637c746
a7e501b
ed8a8c7
750110a
ccaf48d
b334a73
265ea56
945ef3c
6eefda5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3781,7 +3781,7 @@ features: | |
| .. versionadded:: 3.10 | ||
|
|
||
|
|
||
| .. function:: timerfd_create(clockid, /, *, flags) | ||
| .. function:: timerfd_create(clockid, /, *, flags=0) | ||
|
|
||
| Create and return a timer file descriptor (*timerfd*). | ||
|
|
||
|
|
@@ -3924,7 +3924,7 @@ features: | |
| .. versionadded:: 3.13 | ||
|
|
||
|
|
||
| .. function:: timerfd_settime(fd, flags=0, /, *, initial=0.0, interval=0.0) | ||
| .. function:: timerfd_settime(fd, /, *, flags=flags, initial=0.0, interval=0.0) | ||
|
|
||
| Alter a timer file descriptor's internal timer. | ||
| This function operates the same interval timer as :func:`timerfd_settime_ns`. | ||
|
|
@@ -3998,7 +3998,7 @@ features: | |
| .. versionadded:: 3.13 | ||
|
|
||
|
|
||
| .. function:: timerfd_settime_ns(fd, flags=0, /, *, initial=0, interval=0) | ||
| .. function:: timerfd_settime_ns(fd, /, *, flags=0, initial=0, interval=0) | ||
|
|
||
| Similar to :func:`timerfd_settime`, but use time as nanoseconds. | ||
| This function operates the same interval timer as :func:`timerfd_settime`. | ||
|
Comment on lines
3943
to
3920
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same notes as above
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AA-Turner |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3950,7 +3950,7 @@ def test_timerfd_initval(self): | |
|
|
||
| def test_timerfd_non_blocking(self): | ||
| size = 8 # read 8 bytes | ||
| fd = os.timerfd_create(time.CLOCK_REALTIME, os.TFD_NONBLOCK) | ||
| fd = os.timerfd_create(time.CLOCK_REALTIME, flags=os.TFD_NONBLOCK) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to test that the FD is actually non-blocking? Maybe using fcntl? |
||
| self.assertNotEqual(fd, -1) | ||
| self.addCleanup(os.close, fd) | ||
|
|
||
|
|
@@ -3969,13 +3969,13 @@ def test_timerfd_negative(self): | |
| for flags in (0, os.TFD_TIMER_ABSTIME, os.TFD_TIMER_ABSTIME|os.TFD_TIMER_CANCEL_ON_SET): | ||
| with self.subTest(flags=flags, initial=initial, interval=interval): | ||
| with self.assertRaises(OSError) as context: | ||
| _, _ = os.timerfd_settime(fd, flags, initial=initial, interval=interval) | ||
| _, _ = os.timerfd_settime(fd, flags=flags, initial=initial, interval=interval) | ||
| self.assertEqual(context.exception.errno, errno.EINVAL) | ||
|
|
||
| with self.assertRaises(OSError) as context: | ||
| initial_ns = int( (10**9) * initial ) | ||
| interval_ns = int( (10**9) * interval ) | ||
| _, _ = os.timerfd_settime_ns(fd, flags, initial=initial_ns, interval=interval_ns) | ||
| _, _ = os.timerfd_settime_ns(fd, flags=flags, initial=initial_ns, interval=interval_ns) | ||
| self.assertEqual(context.exception.errno, errno.EINVAL) | ||
|
|
||
| def test_timerfd_interval(self): | ||
|
|
@@ -4027,7 +4027,7 @@ def test_timerfd_TFD_TIMER_ABSTIME(self): | |
| # not interval timer | ||
| interval = 0 | ||
|
|
||
| _, _ = os.timerfd_settime(fd, os.TFD_TIMER_ABSTIME, initial=initial_expiration, interval=interval) | ||
| _, _ = os.timerfd_settime(fd, flags=os.TFD_TIMER_ABSTIME, initial=initial_expiration, interval=interval) | ||
|
|
||
| # timerfd_gettime | ||
| # Note: timerfd_gettime returns relative values even if TFD_TIMER_ABSTIME is specified. | ||
|
|
@@ -4045,7 +4045,7 @@ def test_timerfd_TFD_TIMER_ABSTIME(self): | |
|
|
||
| def test_timerfd_select(self): | ||
| size = 8 # read 8 bytes | ||
| fd = os.timerfd_create(time.CLOCK_REALTIME, os.TFD_NONBLOCK) | ||
| fd = os.timerfd_create(time.CLOCK_REALTIME, flags=os.TFD_NONBLOCK) | ||
| self.assertNotEqual(fd, -1) | ||
| self.addCleanup(os.close, fd) | ||
|
|
||
|
|
@@ -4074,7 +4074,7 @@ def test_timerfd_select(self): | |
|
|
||
| def test_timerfd_epoll(self): | ||
| size = 8 # read 8 bytes | ||
| fd = os.timerfd_create(time.CLOCK_REALTIME, os.TFD_NONBLOCK) | ||
| fd = os.timerfd_create(time.CLOCK_REALTIME, flags=os.TFD_NONBLOCK) | ||
| self.assertNotEqual(fd, -1) | ||
| self.addCleanup(os.close, fd) | ||
|
|
||
|
|
@@ -4190,7 +4190,7 @@ def test_timerfd_ns_TFD_TIMER_ABSTIME(self): | |
| # not interval timer | ||
| interval_ns = 0 | ||
|
|
||
| _, _ = os.timerfd_settime_ns(fd, os.TFD_TIMER_ABSTIME, initial=initial_expiration_ns, interval=interval_ns) | ||
| _, _ = os.timerfd_settime_ns(fd, flags=os.TFD_TIMER_ABSTIME, initial=initial_expiration_ns, interval=interval_ns) | ||
|
|
||
| # timerfd_gettime | ||
| # Note: timerfd_gettime returns relative values even if TFD_TIMER_ABSTIME is specified. | ||
|
|
@@ -4210,7 +4210,7 @@ def test_timerfd_ns_select(self): | |
| size = 8 # read 8 bytes | ||
| one_sec_in_nsec = 10**9 | ||
|
|
||
| fd = os.timerfd_create(time.CLOCK_REALTIME, os.TFD_NONBLOCK) | ||
| fd = os.timerfd_create(time.CLOCK_REALTIME, flags=os.TFD_NONBLOCK) | ||
| self.assertNotEqual(fd, -1) | ||
| self.addCleanup(os.close, fd) | ||
|
|
||
|
|
@@ -4240,7 +4240,7 @@ def test_timerfd_ns_select(self): | |
| def test_timerfd_ns_epoll(self): | ||
| size = 8 # read 8 bytes | ||
| one_sec_in_nsec = 10**9 | ||
| fd = os.timerfd_create(time.CLOCK_REALTIME, os.TFD_NONBLOCK) | ||
| fd = os.timerfd_create(time.CLOCK_REALTIME, flags=os.TFD_NONBLOCK) | ||
| self.assertNotEqual(fd, -1) | ||
| self.addCleanup(os.close, fd) | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
|
AA-Turner marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10136,6 +10136,8 @@ os.timerfd_create | |
| time.CLOCK_BOOTTIME | ||
| Same as time.CLOCK_MONOTONIC except that it inclues any time that | ||
| the system is suspended. | ||
| / | ||
| * | ||
| flags: int = 0 | ||
| 0 or a bit mask of os.TFD_NONBLOCK or os.TFD_CLOEXEC. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is enough. The rest should be in the documentation. |
||
|
|
||
|
|
@@ -10145,14 +10147,13 @@ os.timerfd_create | |
|
|
||
| os.TFD_CLOEXEC | ||
| If *TFD_CLOEXEC* is set as a flag, enable the close-on-exec flag | ||
| / | ||
|
|
||
| Create and return a timer file descriptor. | ||
| [clinic start generated code]*/ | ||
|
|
||
| static PyObject * | ||
| os_timerfd_create_impl(PyObject *module, int clockid, int flags) | ||
| /*[clinic end generated code: output=1caae80fb168004a input=0d6b3fdd3ff34dc3]*/ | ||
| /*[clinic end generated code: output=1caae80fb168004a input=f23bfa49fc4b6576]*/ | ||
|
|
||
| { | ||
| int fd; | ||
|
|
@@ -10170,10 +10171,10 @@ os.timerfd_settime | |
|
|
||
| fd: fildes | ||
| A timer file descriptor. | ||
| flags: int = 0 | ||
| 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET. | ||
| / | ||
| * | ||
| flags: int = 0 | ||
| 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET. | ||
| initial: double = 0.0 | ||
| The initial expiration time, in seconds. | ||
|
|
||
|
|
@@ -10193,7 +10194,7 @@ Alter a timer file descriptor's internal timer in seconds. | |
| static PyObject * | ||
| os_timerfd_settime_impl(PyObject *module, int fd, int flags, double initial, | ||
| double interval) | ||
| /*[clinic end generated code: output=0dda31115317adb9 input=af8570ae7e9835d2]*/ | ||
| /*[clinic end generated code: output=0dda31115317adb9 input=436a433c2c9664f0]*/ | ||
| { | ||
| struct itimerspec new_value; | ||
| struct itimerspec old_value; | ||
|
|
@@ -10217,10 +10218,10 @@ os.timerfd_settime_ns | |
|
|
||
| fd: fildes | ||
| A timer file descriptor. | ||
| flags: int = 0 | ||
| 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET. | ||
| / | ||
| * | ||
| flags: int = 0 | ||
| 0 or a bit mask of TFD_TIMER_ABSTIME or TFD_TIMER_CANCEL_ON_SET. | ||
| initial: long_long = 0 | ||
| initial expiration timing in seconds. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same changes as to timerfd_settime
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AA-Turner |
||
|
|
||
|
|
@@ -10240,7 +10241,7 @@ Alter a timer file descriptor's internal timer in nanoseconds. | |
| static PyObject * | ||
| os_timerfd_settime_ns_impl(PyObject *module, int fd, int flags, | ||
| long long initial, long long interval) | ||
| /*[clinic end generated code: output=6273ec7d7b4cc0b3 input=b351df41eb72128e]*/ | ||
| /*[clinic end generated code: output=6273ec7d7b4cc0b3 input=81eb655e9802cb05]*/ | ||
| { | ||
| struct itimerspec new_value; | ||
| struct itimerspec old_value; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.