aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2012-12-25 23:54:08 +0100
committerbnewbold <bnewbold@robocracy.org>2012-12-25 23:54:08 +0100
commit00a96b7f582cc05e4d3b9c89623c13242cceab29 (patch)
treed8597324306f617a017f032f611b587aa7d12801
parent0947d0b74a69ee04ad76b28e988197c826b1a027 (diff)
downloadexmachina-00a96b7f582cc05e4d3b9c89623c13242cceab29.tar.gz
exmachina-00a96b7f582cc05e4d3b9c89623c13242cceab29.zip
add atexit socket cleanup
-rwxr-xr-xexmachina.py8
1 files changed, 8 insertions, 0 deletions
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)