Commit 2bb9e56
gh-87512: Fix subprocess communicate() timeout on Windows for large stdin
On Windows, Popen._communicate() previously wrote to stdin synchronously,
which could block indefinitely if the subprocess didn't consume input
quickly and the pipe buffer filled up. The timeout parameter was only
checked when joining the reader threads, not during the stdin write.
This change moves the stdin writing to a background thread (similar to
how stdout/stderr are read in threads), allowing the timeout to be
properly enforced. If timeout expires, TimeoutExpired is raised promptly
and the writer thread continues in the background. Subsequent calls to
communicate() will join the existing writer thread.
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent 9b7fe29 commit 2bb9e56
1 file changed
+21
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1613 | 1613 | | |
1614 | 1614 | | |
1615 | 1615 | | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
1616 | 1620 | | |
1617 | 1621 | | |
1618 | 1622 | | |
| |||
1631 | 1635 | | |
1632 | 1636 | | |
1633 | 1637 | | |
1634 | | - | |
1635 | | - | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
1636 | 1655 | | |
1637 | 1656 | | |
1638 | 1657 | | |
| |||
0 commit comments