From 287d09a3a0da708bb28ec4e3bfb13621f8ad2316 Mon Sep 17 00:00:00 2001 From: Soumendra Ganguly Date: Sun, 5 Feb 2023 15:31:26 -0600 Subject: [PATCH 1/7] Use os.login_tty() in pty.fork() on systems that lack os.forkpty(). Signed-off-by: Soumendra Ganguly --- Lib/pty.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/Lib/pty.py b/Lib/pty.py index 03073f07c92c05..b2b08405601ec0 100644 --- a/Lib/pty.py +++ b/Lib/pty.py @@ -101,20 +101,8 @@ def fork(): master_fd, slave_fd = openpty() pid = os.fork() if pid == CHILD: - # Establish a new session. - os.setsid() os.close(master_fd) - - # Slave becomes stdin/stdout/stderr of child. - os.dup2(slave_fd, STDIN_FILENO) - os.dup2(slave_fd, STDOUT_FILENO) - os.dup2(slave_fd, STDERR_FILENO) - if slave_fd > STDERR_FILENO: - os.close(slave_fd) - - # Explicitly open the tty to make it become a controlling tty. - tmp_fd = os.open(os.ttyname(STDOUT_FILENO), os.O_RDWR) - os.close(tmp_fd) + os.login_tty(slave_fd) else: os.close(slave_fd) From 89faf29902ac15eacd1b3131a50fbe20c35344da Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 5 Feb 2023 21:40:18 +0000 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-02-05-21-40-15.gh-issue-85984.Kfzbb2.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-02-05-21-40-15.gh-issue-85984.Kfzbb2.rst diff --git a/Misc/NEWS.d/next/Library/2023-02-05-21-40-15.gh-issue-85984.Kfzbb2.rst b/Misc/NEWS.d/next/Library/2023-02-05-21-40-15.gh-issue-85984.Kfzbb2.rst new file mode 100644 index 00000000000000..68b7e6c6c0a91b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-02-05-21-40-15.gh-issue-85984.Kfzbb2.rst @@ -0,0 +1 @@ +Changes the implementation of :func:`pty.fork` to use :func:`os.login_tty` on systems lacking :func:`os.forkpty`. From 1473bf56e25ac759c3d6753442e014935ebe38a8 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 5 Feb 2023 16:55:53 -0800 Subject: [PATCH 3/7] Add DeprecationWarning to master_open and slave_open --- Lib/pty.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/pty.py b/Lib/pty.py index b2b08405601ec0..c71abffc699eb7 100644 --- a/Lib/pty.py +++ b/Lib/pty.py @@ -39,6 +39,9 @@ def master_open(): """master_open() -> (master_fd, slave_name) Open a pty master and return the fd, and the filename of the slave end. Deprecated, use openpty() instead.""" + + import warnings + warnings.warn("Use pty.openpty() instead.", DeprecationWarning, stacklevel=2) # Remove API in 3.14 try: master_fd, slave_fd = os.openpty() @@ -69,6 +72,9 @@ def slave_open(tty_name): opened filedescriptor. Deprecated, use openpty() instead.""" + import warnings + warnings.warn("Use pty.openpty() instead.", DeprecationWarning, stacklevel=2) # Remove API in 3.14 + result = os.open(tty_name, os.O_RDWR) try: from fcntl import ioctl, I_PUSH From 662d81d4e15a79e88065b10a6d5545b312269389 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 5 Feb 2023 16:59:12 -0800 Subject: [PATCH 4/7] mention the deprecation warnings in NEWS --- .../next/Library/2023-02-05-21-40-15.gh-issue-85984.Kfzbb2.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Misc/NEWS.d/next/Library/2023-02-05-21-40-15.gh-issue-85984.Kfzbb2.rst b/Misc/NEWS.d/next/Library/2023-02-05-21-40-15.gh-issue-85984.Kfzbb2.rst index 68b7e6c6c0a91b..6c47a1e45c0f12 100644 --- a/Misc/NEWS.d/next/Library/2023-02-05-21-40-15.gh-issue-85984.Kfzbb2.rst +++ b/Misc/NEWS.d/next/Library/2023-02-05-21-40-15.gh-issue-85984.Kfzbb2.rst @@ -1 +1,4 @@ Changes the implementation of :func:`pty.fork` to use :func:`os.login_tty` on systems lacking :func:`os.forkpty`. + +A :exc:`DeprecationWarning` is now raised by ``pty.master_open()`` and ``pty.slave_open()``. They were +undocumented and deprecated long long ago in the docstring in favor of :func:`pty.openpty`. From 820bc050c9666c0262047c3da4fa60f0728d8b65 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 5 Feb 2023 17:02:39 -0800 Subject: [PATCH 5/7] Add a whatsnew entry regarding the 3.14 removals. --- Doc/whatsnew/3.12.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 0c5a70b64574ef..747b380fcc5a98 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -512,6 +512,10 @@ Pending Removal in Python 3.14 :func:`~multiprocessing.set_start_method` APIs to explicitly specify when your code *requires* ``'fork'``. See :ref:`multiprocessing-start-methods`. +* :mod:`pty` has two undocumented ``master_open()`` and ``slave_open()`` + functions that have been deprecated since Python 2 but only gained a + proper :exc:`DeprecationWarning` in 3.12. Remove them in 3.14. + Pending Removal in Future Versions ---------------------------------- From b0bead8ef6a3ec145281b83dc1e6750f871073a6 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Mon, 6 Feb 2023 01:02:47 -0800 Subject: [PATCH 6/7] fix whitespace --- Lib/pty.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/pty.py b/Lib/pty.py index c71abffc699eb7..6571050886bd1d 100644 --- a/Lib/pty.py +++ b/Lib/pty.py @@ -39,7 +39,7 @@ def master_open(): """master_open() -> (master_fd, slave_name) Open a pty master and return the fd, and the filename of the slave end. Deprecated, use openpty() instead.""" - + import warnings warnings.warn("Use pty.openpty() instead.", DeprecationWarning, stacklevel=2) # Remove API in 3.14 From 4287962595375f1abf21c41c0949a33536491774 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Tue, 7 Feb 2023 01:15:44 -0800 Subject: [PATCH 7/7] updated news wording --- .../next/Library/2023-02-05-21-40-15.gh-issue-85984.Kfzbb2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-02-05-21-40-15.gh-issue-85984.Kfzbb2.rst b/Misc/NEWS.d/next/Library/2023-02-05-21-40-15.gh-issue-85984.Kfzbb2.rst index 6c47a1e45c0f12..c91829f2c739af 100644 --- a/Misc/NEWS.d/next/Library/2023-02-05-21-40-15.gh-issue-85984.Kfzbb2.rst +++ b/Misc/NEWS.d/next/Library/2023-02-05-21-40-15.gh-issue-85984.Kfzbb2.rst @@ -1,4 +1,4 @@ -Changes the implementation of :func:`pty.fork` to use :func:`os.login_tty` on systems lacking :func:`os.forkpty`. +Refactored the implementation of :func:`pty.fork` to use :func:`os.login_tty`. A :exc:`DeprecationWarning` is now raised by ``pty.master_open()`` and ``pty.slave_open()``. They were undocumented and deprecated long long ago in the docstring in favor of :func:`pty.openpty`. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy