New submission from Cornelius Diekmann:
My OS: Debian GNU/Linux 8.6 (jessie)
Python 3.4.2
pty.py from Python-3.5.2/Lib (pty.py is just a tiny, portable python file which
did not see many changes)
Bug Report
Steps to Reproduce:
I wrote a very simple python remote shell:
#!/usr/bin/env python3
import pty
pty.spawn('/bin/sh')
It can be run in a terminal (call it TermA) with `nc -e
./myfancypythonremoteshell.py -l -p 6699`
In a different terminal (call it TermB), I connect to my fancy remote shell
with `nc 127.0.0.1 6699`.
The shell works fine. In TermB, I quit by pressing ctrl+c.
Observed Behavior: In TermA, the nc process, the python process, and the
spawned /bin/sh still exist. They still occupy TermA.
Expected Behavior: The client in TermB has disconnected, /bin/sh in TermA can
no longer read anything from stdin and it should close down. Ultimately, in
TermA, nc should have exited successfully.
Fix: End the _copy loop in pty.py once EOF in STDIN is reached. Everything
shuts itself down automatically. I included a small patch to demonstrate this
behavior.
This patch is not meant to go straight into production. I have not verified if
this behavior somehow breaks other use cases. This bug report is meant to
document exactly one specific use case and supply exactly one line of code
change for it.
This issue is related to issue26228. Actually, it is complementary. issue26228
wants to return if master_fd is EOF, this issue wants to return if stdin is
EOF. Both behaviors together looks good to me. By the way, I hacked a hacky
`assert False` into my patch as a placeholder for issue26228's proper handling
of exec failures at that part of the code.
I suggest to combine the patches of this issue and issue26228.
----------
components: Library (Lib)
files: pty.patch
keywords: patch
messages: 283880
nosy: Cornelius Diekmann, martin.panter
priority: normal
severity: normal
status: open
title: pty.py: pty.spawn hangs after client disconnect over nc (netcat)
type: enhancement
versions: Python 3.4, Python 3.5
Added file: http://bugs.python.org/file46006/pty.patch
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue29054>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com