Companion: ensure sockets get closed

- Should fix #293
This commit is contained in:
tomkat83 2017-05-12 08:22:36 +02:00
parent 5bc9a60ad4
commit b555ccce00

View file

@ -144,7 +144,24 @@ class PlexCompanion(Thread):
offset=data.get('offset')) offset=data.get('offset'))
def run(self): def run(self):
httpd = False # Ensure that sockets will be closed no matter what
try:
self.__run()
finally:
try:
self.httpd.socket.shutdown(SHUT_RDWR)
except AttributeError:
pass
finally:
try:
self.httpd.socket.close()
except AttributeError:
pass
log.info("----===## Plex Companion stopped ##===----")
def __run(self):
self.httpd = False
httpd = self.httpd
# Cache for quicker while loops # Cache for quicker while loops
client = self.client client = self.client
threadStopped = self.threadStopped threadStopped = self.threadStopped
@ -245,11 +262,3 @@ class PlexCompanion(Thread):
sleep(50) sleep(50)
client.stop_all() client.stop_all()
if httpd:
try:
httpd.socket.shutdown(SHUT_RDWR)
except:
pass
finally:
httpd.socket.close()
log.info("----===## Plex Companion stopped ##===----")