Skip to content

Commit 631f7d7

Browse files
committed
docs: keep subprocess snippets lintable
1 parent 593a91e commit 631f7d7

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

docs/run/index.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,20 @@ reader. If your tool starts a subprocess and you do not intend to feed it input,
4747
redirect the child's stdin:
4848

4949
```python
50-
process = await asyncio.create_subprocess_exec(
51-
sys.executable,
52-
"script.py",
53-
stdin=subprocess.DEVNULL,
54-
stdout=subprocess.PIPE,
55-
stderr=subprocess.PIPE,
56-
)
50+
import asyncio
51+
import subprocess
52+
import sys
53+
54+
55+
async def run_script() -> tuple[bytes, bytes]:
56+
process = await asyncio.create_subprocess_exec(
57+
sys.executable,
58+
"script.py",
59+
stdin=subprocess.DEVNULL,
60+
stdout=subprocess.PIPE,
61+
stderr=subprocess.PIPE,
62+
)
63+
return await process.communicate()
5764
```
5865

5966
The matching troubleshooting entry is **[My stdio tool hangs when it starts a subprocess on Windows](../troubleshooting.md#my-stdio-tool-hangs-when-it-starts-a-subprocess-on-windows)**.

docs/troubleshooting.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,20 @@ same pipe.
156156
If you do not intend to send input to the child, redirect its stdin:
157157

158158
```python
159-
process = await asyncio.create_subprocess_exec(
160-
sys.executable,
161-
"script.py",
162-
stdin=subprocess.DEVNULL,
163-
stdout=subprocess.PIPE,
164-
stderr=subprocess.PIPE,
165-
)
159+
import asyncio
160+
import subprocess
161+
import sys
162+
163+
164+
async def run_script() -> tuple[bytes, bytes]:
165+
process = await asyncio.create_subprocess_exec(
166+
sys.executable,
167+
"script.py",
168+
stdin=subprocess.DEVNULL,
169+
stdout=subprocess.PIPE,
170+
stderr=subprocess.PIPE,
171+
)
172+
return await process.communicate()
166173
```
167174

168175
Use the same idea with `subprocess.Popen(..., stdin=subprocess.DEVNULL)`. Also

0 commit comments

Comments
 (0)