import os, socket p = "/tmp/test.sock" if os.path.exists(p): os.remove(p) srv = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) try: srv.bind(p) srv.listen(1) print("bound, listening") print("exists immediately after bind:", os.path.exists(p)) finally: srv.close() if os.path.exists(p): os.remove(p)