From 00a96b7f582cc05e4d3b9c89623c13242cceab29 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Tue, 25 Dec 2012 23:54:08 +0100 Subject: add atexit socket cleanup --- exmachina.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/exmachina.py b/exmachina.py index 3ed6a96..d255f4c 100755 --- a/exmachina.py +++ b/exmachina.py @@ -40,6 +40,7 @@ import time import base64 import functools import hashlib +import atexit import bjsonrpc import bjsonrpc.handlers @@ -347,6 +348,13 @@ def run_server(socket_path, secret_key=None, socket_group=None): sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.bind(socket_path) + # we just created the socket file, so now let's register an atexit callback + # to clean up after ourselves if we get Ctrl-C'd (or exit for any other + # reason, including normal cleanup) + def delete_socket(): + os.unlink(socket_path) + atexit.register(delete_socket) + # only going to allow a single client, so don't allow queued connections sock.listen(0) -- cgit v1.2.3