diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-03-30 06:33:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-30 06:33:02 (GMT) |
commit | 172bb39452ae8b3ccdf5d1f23ead46f44200cd49 (patch) | |
tree | 5e1effbca3664b839a81eb7a7d62fa4974cfbfb1 /Tools/demo/rpythond.py | |
parent | afbb7a371fb44edc731344eab5b474ad8f7b57d7 (diff) | |
download | cpython-172bb39452ae8b3ccdf5d1f23ead46f44200cd49.zip cpython-172bb39452ae8b3ccdf5d1f23ead46f44200cd49.tar.gz cpython-172bb39452ae8b3ccdf5d1f23ead46f44200cd49.tar.bz2 |
bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927)
Diffstat (limited to 'Tools/demo/rpythond.py')
-rwxr-xr-x | Tools/demo/rpythond.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/Tools/demo/rpythond.py b/Tools/demo/rpythond.py index 9ffe13a..a885b3e 100755 --- a/Tools/demo/rpythond.py +++ b/Tools/demo/rpythond.py @@ -26,16 +26,16 @@ def main(): s.listen(1) while True: conn, (remotehost, remoteport) = s.accept() - print('connection from', remotehost, remoteport) - request = b'' - while 1: - data = conn.recv(BUFSIZE) - if not data: - break - request += data - reply = execute(request.decode()) - conn.send(reply.encode()) - conn.close() + with conn: + print('connection from', remotehost, remoteport) + request = b'' + while 1: + data = conn.recv(BUFSIZE) + if not data: + break + request += data + reply = execute(request.decode()) + conn.send(reply.encode()) def execute(request): stdout = sys.stdout |