Remove socket after server close

This commit is contained in:
Jake Howard 2018-12-08 13:09:38 +00:00
parent d88eecc0da
commit 1352e49f11
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -1,6 +1,7 @@
import socket import socket
import socketserver import socketserver
import threading import threading
import os
import ujson import ujson
from ipc_unix.utils import read_payload from ipc_unix.utils import read_payload
@ -28,7 +29,8 @@ class Server:
class InstanceRequestHandler(RequestHandler): class InstanceRequestHandler(RequestHandler):
handle_request = self.handle_request handle_request = self.handle_request
self.server = socketserver.UnixStreamServer(socket_path, InstanceRequestHandler) self.socket_path = socket_path
self.server = socketserver.UnixStreamServer(self.socket_path, InstanceRequestHandler)
def serve_forever(self): def serve_forever(self):
self.server.serve_forever() self.server.serve_forever()
@ -41,6 +43,7 @@ class Server:
def close(self): def close(self):
self.server.shutdown() self.server.shutdown()
self.server.server_close() self.server.server_close()
os.remove(self.socket_path)
def handle_request(self, request: dict): def handle_request(self, request: dict):
raise NotImplementedError("Must override `handle_request`") raise NotImplementedError("Must override `handle_request`")