Ensure LinuxListener.close can be called multiple times

This commit is contained in:
Kovid Goyal 2020-10-17 13:08:49 +05:30
parent 3686dc929c
commit fc77917e9c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -123,8 +123,11 @@ if islinux:
# shutdown() not close(). This is needed to allow calibre to
# restart using the same socket address.
import socket
self._listener._socket.shutdown(socket.SHUT_RDWR)
self._listener._socket.close()
listener = self._listener
if listener is not None:
self._listener = None
listener._socket.shutdown(socket.SHUT_RDWR)
listener._socket.close()
def accept(self, *args, **kwargs):
ans = Listener.accept(self, *args, **kwargs)