Commit b46ebd6
g97iulio1609
fix: prevent stdio transport from closing real stdin/stdout
When using transport='stdio', the server wraps sys.stdin.buffer and
sys.stdout.buffer in TextIOWrapper and anyio.AsyncFile. When these
wrappers are garbage collected after the server exits, they close
the underlying sys.stdin/sys.stdout, causing subsequent I/O
operations to fail with ValueError.
Use os.dup() to duplicate the file descriptors before wrapping them,
so closing the wrapped streams only closes the duplicates, leaving
the original stdin/stdout intact.
Fixes #19331 parent 62575ed commit b46ebd6
1 file changed
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
| 43 | + | |
41 | 44 | | |
42 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
43 | 48 | | |
44 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
45 | 52 | | |
46 | 53 | | |
47 | 54 | | |
| |||
0 commit comments