From d54539f25bbfb028bfe75c877200b76690eb45d4 Mon Sep 17 00:00:00 2001 From: pyldap contributors Date: Thu, 23 Nov 2017 22:39:24 +0100 Subject: [PATCH] slapdtest: Ensure server is stopped when the process exits --- Lib/slapdtest.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/slapdtest.py b/Lib/slapdtest.py index 2580ef3..1aba887 100644 --- a/Lib/slapdtest.py +++ b/Lib/slapdtest.py @@ -12,6 +12,7 @@ import time import subprocess import logging +import atexit from logging.handlers import SysLogHandler import unittest @@ -151,6 +152,9 @@ def _cleanup_rundir(self): """ Recursively delete whole directory specified by `path' """ + # cleanup_rundir() is called in atexit handler. Until Python 3.4, + # the rest of the world is already destroyed. + import os, os.path if not os.path.exists(self.testrundir): return self._log.debug('clean-up %s', self.testrundir) @@ -278,6 +282,7 @@ def start(self): if self._proc is None: # prepare directory structure + atexit.register(self.stop) self._cleanup_rundir() self.setup_rundir() self._write_config()