diff options
author | Davide Rizzo <sorcio@gmail.com> | 2023-11-04 21:45:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-04 21:45:24 (GMT) |
commit | a6c1c04d4d2339f0094422974ae3f26f8c7c8565 (patch) | |
tree | 3beb522a8fba439d928b2ab485b7c8125a1cfe78 /Lib/test/test_kqueue.py | |
parent | cd6b2ced7595fa69222bdd2042edc5a2576f3678 (diff) | |
download | cpython-a6c1c04d4d2339f0094422974ae3f26f8c7c8565.zip cpython-a6c1c04d4d2339f0094422974ae3f26f8c7c8565.tar.gz cpython-a6c1c04d4d2339f0094422974ae3f26f8c7c8565.tar.bz2 |
gh-110395: invalidate open kqueues after fork (#110517)
Invalidate open select.kqueue instances after fork as the fd will be invalid in the child.
Diffstat (limited to 'Lib/test/test_kqueue.py')
-rw-r--r-- | Lib/test/test_kqueue.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_kqueue.py b/Lib/test/test_kqueue.py index 998fd9d..28e882b 100644 --- a/Lib/test/test_kqueue.py +++ b/Lib/test/test_kqueue.py @@ -5,6 +5,7 @@ import errno import os import select import socket +from test import support import time import unittest @@ -256,6 +257,23 @@ class TestKQueue(unittest.TestCase): self.addCleanup(kqueue.close) self.assertEqual(os.get_inheritable(kqueue.fileno()), False) + @support.requires_fork() + def test_fork(self): + # gh-110395: kqueue objects must be closed after fork + kqueue = select.kqueue() + if (pid := os.fork()) == 0: + try: + self.assertTrue(kqueue.closed) + with self.assertRaisesRegex(ValueError, "closed kqueue"): + kqueue.fileno() + except: + os._exit(1) + finally: + os._exit(0) + else: + self.assertFalse(kqueue.closed) + support.wait_process(pid, exitcode=0) + if __name__ == "__main__": unittest.main() |