From 52720be90d50330f4db43b5596c1fff4d59410a2 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Wed, 16 Oct 2019 19:57:05 +0900 Subject: [PATCH 1/6] bpo-38493: Add os.CLD_KILLED for posix module --- Doc/library/os.rst | 1 + .../next/Library/2019-10-16-19-56-51.bpo-38373.86ExWB.rst | 2 ++ Modules/posixmodule.c | 3 +++ 3 files changed, 6 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2019-10-16-19-56-51.bpo-38373.86ExWB.rst diff --git a/Doc/library/os.rst b/Doc/library/os.rst index fe9531b1701771..96daead124e442 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3946,6 +3946,7 @@ written in Python, such as a mail server's external command delivery program. .. data:: CLD_EXITED + CLD_KILLED CLD_DUMPED CLD_TRAPPED CLD_CONTINUED diff --git a/Misc/NEWS.d/next/Library/2019-10-16-19-56-51.bpo-38373.86ExWB.rst b/Misc/NEWS.d/next/Library/2019-10-16-19-56-51.bpo-38373.86ExWB.rst new file mode 100644 index 00000000000000..c79f0f537968f4 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-10-16-19-56-51.bpo-38373.86ExWB.rst @@ -0,0 +1,2 @@ +:data:`~os.CLD_KILLED` is added for posixmodule. +(Contributed by Dong-hee Na in :issue:`38493`.) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 3c4e254abb56dd..e8a8b16d99084f 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -14057,6 +14057,9 @@ all_ins(PyObject *m) #ifdef CLD_EXITED if (PyModule_AddIntMacro(m, CLD_EXITED)) return -1; #endif +#ifdef CLD_KILLED + if (PyModule_AddIntMacro(m, CLD_KILLED)) return -1; +#endif #ifdef CLD_DUMPED if (PyModule_AddIntMacro(m, CLD_DUMPED)) return -1; #endif From 7cbcb5da38b0c9702a4c2eb06158bb6caedaef82 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Wed, 16 Oct 2019 22:07:23 +0900 Subject: [PATCH 2/6] bpo-38493: Add unit test --- Lib/test/test_posix.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 9bdd2848afc81b..e254461f55b6b5 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -1226,6 +1226,18 @@ def test_rename_dir_fd(self): finally: posix.close(f) + @unittest.skipUnless(hasattr(signal, 'SIGCHLD'), 'CLD_XXXX be placed in si_code for a SIGCHLD signal') + @unittest.skipUnless(hasattr(posix, 'waitid_result'), "test needs posix.waitid_result") + def test_cld_xxxx_constants(self): + # reference: http://man7.org/linux/man-pages/man2/sigaction.2.html + self.assertEqual(posix.CLD_EXITED, 1) + self.assertEqual(posix.CLD_KILLED, 2) + self.assertEqual(posix.CLD_DUMPED, 3) + self.assertEqual(posix.CLD_TRAPPED, 4) + self.assertEqual(posix.CLD_STOPPED, 5) + # FIXME: CLD_CONTINUED was added since Linux 2.6.9 + # self.assertEqual(posix.CLD_CONTINUED, 6) + @unittest.skipUnless(os.symlink in os.supports_dir_fd, "test needs dir_fd support in os.symlink()") def test_symlink_dir_fd(self): f = posix.open(posix.getcwd(), posix.O_RDONLY) From 6ee7cca8cdaff82d647159f9d0e903afb4a3c69b Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Wed, 16 Oct 2019 22:12:34 +0900 Subject: [PATCH 3/6] bpo-38493: Add CLD_STOPPED and update documentation --- Doc/library/os.rst | 4 ++++ Doc/whatsnew/3.9.rst | 6 ++++++ Lib/test/test_posix.py | 14 +++++++------- .../2019-10-16-19-56-51.bpo-38373.86ExWB.rst | 2 -- .../2019-10-16-19-56-51.bpo-38493.86ExWB.rst | 2 ++ Modules/posixmodule.c | 3 +++ 6 files changed, 22 insertions(+), 9 deletions(-) delete mode 100644 Misc/NEWS.d/next/Library/2019-10-16-19-56-51.bpo-38373.86ExWB.rst create mode 100644 Misc/NEWS.d/next/Library/2019-10-16-19-56-51.bpo-38493.86ExWB.rst diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 96daead124e442..8e9d9e6f034e3a 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3949,6 +3949,7 @@ written in Python, such as a mail server's external command delivery program. CLD_KILLED CLD_DUMPED CLD_TRAPPED + CLD_STOPPED CLD_CONTINUED These are the possible values for :attr:`si_code` in the result returned by @@ -3958,6 +3959,9 @@ written in Python, such as a mail server's external command delivery program. .. versionadded:: 3.3 + .. versionchanged:: 3.9 + Added :data:`CLD_KILLED` and :data:`CLD_STOPPED` values. + .. function:: waitpid(pid, options) diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index 6b4abc0567c30e..f203930fd1b7b7 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -125,6 +125,12 @@ that schedules a shutdown for the default executor that waits on the :func:`asyncio.run` has been updated to use the new :term:`coroutine`. (Contributed by Kyle Stanley in :issue:`34037`.) +os +__ + +Added :data:`~os.CLD_KILLED` and :data:`~os.CLD_STOPPED` for :attr:`si_code`. +(Contributed by Dong-hee Na in :issue:`38493`.) + threading --------- diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index e254461f55b6b5..5cedbf73dc4500 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -1227,16 +1227,16 @@ def test_rename_dir_fd(self): posix.close(f) @unittest.skipUnless(hasattr(signal, 'SIGCHLD'), 'CLD_XXXX be placed in si_code for a SIGCHLD signal') - @unittest.skipUnless(hasattr(posix, 'waitid_result'), "test needs posix.waitid_result") + @unittest.skipUnless(hasattr(os, 'waitid_result'), "test needs posix.waitid_result") def test_cld_xxxx_constants(self): # reference: http://man7.org/linux/man-pages/man2/sigaction.2.html - self.assertEqual(posix.CLD_EXITED, 1) - self.assertEqual(posix.CLD_KILLED, 2) - self.assertEqual(posix.CLD_DUMPED, 3) - self.assertEqual(posix.CLD_TRAPPED, 4) - self.assertEqual(posix.CLD_STOPPED, 5) + self.assertEqual(os.CLD_EXITED, 1) + self.assertEqual(os.CLD_KILLED, 2) + self.assertEqual(os.CLD_DUMPED, 3) + self.assertEqual(os.CLD_TRAPPED, 4) + self.assertEqual(os.CLD_STOPPED, 5) # FIXME: CLD_CONTINUED was added since Linux 2.6.9 - # self.assertEqual(posix.CLD_CONTINUED, 6) + # self.assertEqual(os.CLD_CONTINUED, 6) @unittest.skipUnless(os.symlink in os.supports_dir_fd, "test needs dir_fd support in os.symlink()") def test_symlink_dir_fd(self): diff --git a/Misc/NEWS.d/next/Library/2019-10-16-19-56-51.bpo-38373.86ExWB.rst b/Misc/NEWS.d/next/Library/2019-10-16-19-56-51.bpo-38373.86ExWB.rst deleted file mode 100644 index c79f0f537968f4..00000000000000 --- a/Misc/NEWS.d/next/Library/2019-10-16-19-56-51.bpo-38373.86ExWB.rst +++ /dev/null @@ -1,2 +0,0 @@ -:data:`~os.CLD_KILLED` is added for posixmodule. -(Contributed by Dong-hee Na in :issue:`38493`.) diff --git a/Misc/NEWS.d/next/Library/2019-10-16-19-56-51.bpo-38493.86ExWB.rst b/Misc/NEWS.d/next/Library/2019-10-16-19-56-51.bpo-38493.86ExWB.rst new file mode 100644 index 00000000000000..1a4bef65d4318f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-10-16-19-56-51.bpo-38493.86ExWB.rst @@ -0,0 +1,2 @@ +Added :data:`~os.CLD_KILLED` and :data:`~os.CLD_STOPPED` for :attr:`si_code`. +Patch by Dong-hee Na. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index e8a8b16d99084f..d49728406878fd 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -14066,6 +14066,9 @@ all_ins(PyObject *m) #ifdef CLD_TRAPPED if (PyModule_AddIntMacro(m, CLD_TRAPPED)) return -1; #endif +#ifdef CLD_STOPPED + if (PyModule_AddIntMacro(m, CLD_STOPPED)) return -1; +#endif #ifdef CLD_CONTINUED if (PyModule_AddIntMacro(m, CLD_CONTINUED)) return -1; #endif From bb6589fc12bf8d13075866497f76df0bd6b6415d Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Wed, 16 Oct 2019 22:59:21 +0900 Subject: [PATCH 4/6] update --- Lib/test/test_posix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 5cedbf73dc4500..3af359189fb05a 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -1227,7 +1227,7 @@ def test_rename_dir_fd(self): posix.close(f) @unittest.skipUnless(hasattr(signal, 'SIGCHLD'), 'CLD_XXXX be placed in si_code for a SIGCHLD signal') - @unittest.skipUnless(hasattr(os, 'waitid_result'), "test needs posix.waitid_result") + @unittest.skipUnless(hasattr(os, 'waitid_result'), "test needs os.waitid_result") def test_cld_xxxx_constants(self): # reference: http://man7.org/linux/man-pages/man2/sigaction.2.html self.assertEqual(os.CLD_EXITED, 1) From 8a936a5e8a417f8a2c49d9b682e47631e04afde3 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Wed, 16 Oct 2019 23:19:22 +0900 Subject: [PATCH 5/6] bpo-38493: Update unittest --- Lib/test/test_posix.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 3af359189fb05a..695e83bb00e7b0 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -1229,14 +1229,12 @@ def test_rename_dir_fd(self): @unittest.skipUnless(hasattr(signal, 'SIGCHLD'), 'CLD_XXXX be placed in si_code for a SIGCHLD signal') @unittest.skipUnless(hasattr(os, 'waitid_result'), "test needs os.waitid_result") def test_cld_xxxx_constants(self): - # reference: http://man7.org/linux/man-pages/man2/sigaction.2.html - self.assertEqual(os.CLD_EXITED, 1) - self.assertEqual(os.CLD_KILLED, 2) - self.assertEqual(os.CLD_DUMPED, 3) - self.assertEqual(os.CLD_TRAPPED, 4) - self.assertEqual(os.CLD_STOPPED, 5) - # FIXME: CLD_CONTINUED was added since Linux 2.6.9 - # self.assertEqual(os.CLD_CONTINUED, 6) + self.assertTrue(hasattr(os, 'CLD_EXITED')) + self.assertTrue(hasattr(os, 'CLD_KILLED')) + self.assertTrue(hasattr(os, 'CLD_DUMPED')) + self.assertTrue(hasattr(os, 'CLD_TRAPPED')) + self.assertTrue(hasattr(os, 'CLD_STOPPED')) + self.assertTrue(hasattr(os, 'CLD_CONTINUED')) @unittest.skipUnless(os.symlink in os.supports_dir_fd, "test needs dir_fd support in os.symlink()") def test_symlink_dir_fd(self): From 93e1a698cbadd04a3ebe5fecd7e4613e17433f77 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Mon, 21 Oct 2019 15:38:11 +0900 Subject: [PATCH 6/6] bpo-38493: Update unittest --- Lib/test/test_posix.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 695e83bb00e7b0..17e4ded2e2d695 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -1229,12 +1229,12 @@ def test_rename_dir_fd(self): @unittest.skipUnless(hasattr(signal, 'SIGCHLD'), 'CLD_XXXX be placed in si_code for a SIGCHLD signal') @unittest.skipUnless(hasattr(os, 'waitid_result'), "test needs os.waitid_result") def test_cld_xxxx_constants(self): - self.assertTrue(hasattr(os, 'CLD_EXITED')) - self.assertTrue(hasattr(os, 'CLD_KILLED')) - self.assertTrue(hasattr(os, 'CLD_DUMPED')) - self.assertTrue(hasattr(os, 'CLD_TRAPPED')) - self.assertTrue(hasattr(os, 'CLD_STOPPED')) - self.assertTrue(hasattr(os, 'CLD_CONTINUED')) + os.CLD_EXITED + os.CLD_KILLED + os.CLD_DUMPED + os.CLD_TRAPPED + os.CLD_STOPPED + os.CLD_CONTINUED @unittest.skipUnless(os.symlink in os.supports_dir_fd, "test needs dir_fd support in os.symlink()") def test_symlink_dir_fd(self):