This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pty.fork() compatibility code wrong?
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: akuchling Nosy List: akuchling, rvdp
Priority: normal Keywords: patch

Created on 2003-08-04 20:02 by rvdp, last changed 2022-04-10 16:10 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pty.fork.patch rvdp, 2003-08-04 20:08 Not a real patch, but more readable than my comment
Messages (2)
msg44382 - (view) Author: Patrick Lynch (rvdp) Date: 2003-08-04 20:02
pty.fork() provides compatibility code for environments 
lacking os.forkpty() 
 
This code is incorrect compared to the forkpty code in glibc, 
and will cause reading of the returned master_fd to hang 
indefinetly when the child process is finished. 
 
I am running on linux, Python 2.2. I am using the 
compatibility code where I need more control ( grabing 
stdout seperate to stderr, which is on the pty). 
 
To have it read like forkpty in glibc: 
 
<snip> 
    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) 
    else:#PARENT 
        os.close( slave_fd) 
 
    # Parent and child process. 
    return pid, master_fd 
 
Reading the master_fd when the child is finished will now 
raise an IO error, same as the native forkpty(). 
 
I guess the story may be different on non linux boxen 
 
Patrick. 
msg44383 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2006-12-22 18:42
Applied to the trunk in rev. 53146.  Thanks for pointing out this bug!

History
Date User Action Args
2022-04-10 16:10:28adminsetgithub: 39007
2003-08-04 20:02:38rvdpcreate