Skip to content

Commit

Permalink
Ensure socket closes properly
Browse files Browse the repository at this point in the history
The socket is being held open by the writable handle. Close both the handle and the socket.
To do this we need to store the handle as a member variable.
  • Loading branch information
Sean Perry committed Mar 17, 2016
1 parent cbd7dd7 commit 18cd5a4
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rpdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ def __init__(self, addr=DEFAULT_ADDR, port=DEFAULT_PORT):
stdin=FileObjectWrapper(handle, self.old_stdin),
stdout=FileObjectWrapper(handle, self.old_stdin))
sys.stdout = sys.stdin = handle
self.handle = handle
OCCUPIED.claim(port, sys.stdout)

def shutdown(self):
"""Revert stdin and stdout, close the socket."""
sys.stdout = self.old_stdout
sys.stdin = self.old_stdin
self.handle.close()
OCCUPIED.unclaim(self.port)
self.skt.shutdown(socket.SHUT_RDWR)
self.skt.close()

def do_continue(self, arg):
Expand Down

0 comments on commit 18cd5a4

Please sign in to comment.