Skip to content

Commit 81b1a22

Browse files
committed
Rewrite pty.spawn docs again
1 parent 8c9a632 commit 81b1a22

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

Doc/library/pty.rst

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,28 @@ The :mod:`pty` module defines the following functions:
4343

4444
Spawn a process, and connect its controlling terminal with the current
4545
process's standard io. This is often used to baffle programs which insist on
46-
reading from the controlling terminal.
47-
48-
The functions *master_read* and *stdin_read* are passed a file
49-
descriptor which they should read from, and should return a byte
50-
string. The default implementation for both functions will read up
51-
to 1024 bytes each time the function is called. Returning an empty
52-
byte string is interpreted as an end of file (EOF) condition, and
53-
that *_read* function will no longer be called.
46+
reading from the controlling terminal. It is expected that the process
47+
spawned behind the pty will eventually terminate, and when it does *spawn*
48+
will return.
49+
50+
The functions *master_read* and *stdin_read* are passed a file descriptor
51+
which they should read from, and they should always return a byte
52+
string. Returning an empty byte string from either callback is interpreted as
53+
an end-of-file (EOF) condition, and that callback will not be called after
54+
that.
55+
56+
In general, manually signaling EOF from one of the read callback will not
57+
behave well. If *stdin_read* returns EOF the controlling terminal can no
58+
longer communicate with.
59+
60+
If both callbacks signal EOF then *spawn* will block indefinitely. This
61+
is a bug, documented in `issue 26228 <https://bugs.python.org/issue26228>`_.
62+
63+
The default implementation for both functions will read and return up to 1024
64+
bytes each time the function is called. *Master_read* is passed the
65+
pseudoterminal’s master file descriptor to read output from the child
66+
process, and *stdin_read* is passed file descriptor 0, to read from the
67+
parent process's standard input.
5468

5569
.. versionchanged:: 3.4
5670
:func:`spawn` now returns the status value from :func:`os.waitpid`

0 commit comments

Comments
 (0)