agentscope-ai / agentscope-ai/QwenPaw

Windows: python hangs in execute_shell_command due to inherited stdin pipe (missing stdin=DEVNULL)

Aperta
#7,312 2 commenti 0 reazioni 1 assegnatario Assegnata a @jinglinpeng Vedi su GitHub
Lingua principale
TypeScript
Stelle
35k
Fork
3.1k
Merge medio
1g 13h
PR unite (30g)
228

Descrizione

# Windows: `execute_shell_command` python hangs on inherited stdin pipe

## Environment
- Windows 11 (build 26200.7462)
- QwenPaw Desktop backend (PyInstaller onefile, `qwenpaw-backend.exe`)
- Python 3.14.3 (also reproduced with Python 3.12)

## Symptom
Running any python interpreter through `execute_shell_command` hangs indefinitely:

```
C:\Python314\python.exe -c "print(1)" # HANGS
```

`python --version` returns quickly, but any command that performs a full
interpreter initialization (`-c`, `-S`, `-E`, scripts) hangs.

Same shell command typed manually in `cmd.exe` works instantly.

## Root cause
`QwenPaw` backend spawns `cmd.exe` (via `subprocess.Popen` in
`qwenpaw/agents/tools/shell.py`, and `asyncio.create_subprocess_exec` in
`sandbox/local_sandbox.py`) **without specifying `stdin`**. With `stdin=None`,
the child inherits the parent's stdin handle, which for the backend is a pipe.

`python.exe` then inherits that pipe as stdin and blocks during interpreter
initialization. Redirecting stdin to `nul` fixes it instantly:

```
C:\Python314\python.exe -c "print(1)" < nul # WORKS (instant)
```

## Fix (in working tree)
Add `stdin=subprocess.DEVNULL` (or `stdin=asyncio.subprocess.DEVNULL`) to all
subprocess spawn sites that don't need interactive stdin:

1. `src/qwenpaw/agents/tools/shell.py` — `_execute_subprocess_sync` (`subprocess.Popen`) — **DONE**
2. `src/qwenpaw/agents/tools/shell.py` — POSIX `asyncio.create_subprocess_exec` — **DONE**
3. `src/qwenpaw/sandbox/local_sandbox.py` — `asyncio.create_subprocess_exec` — **DONE**

Reserve `stdin=PIPE` only for processes that genuinely need interactive input.

## Repro
```
python -c "print(1)" # via execute_shell_command → hangs
python -c "print(1)" < nul # via execute_shell_command → prints 1
```

## Suggested change (patch)
```python
proc = subprocess.Popen(
wrapped,
shell=False,
stdin=subprocess.DEVNULL, # ← ADDED
stdout=stdout_file,
stderr=stderr_file,
...
)
```

---
Created by user (Serge) — issue candidate, 2026-08-26.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start in src/qwenpaw/agents/tools/shell.py at _execute_subprocess_sync and the POSIX asyncio.create_subprocess_exec call, then inspect src/qwenpaw/sandbox/local_sandbox.py. Reproduce the reported Python hang through execute_shell_command, verify the listed noninteractive subprocess paths do not inherit the backend pipe, and confirm interactive-input paths remain unaffected.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend, tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Attiva
Chiarezza
Specificata chiaramente
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.