diff options
Diffstat (limited to 'test/functional/util/dummy_killer.py')
-rw-r--r-- | test/functional/util/dummy_killer.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/functional/util/dummy_killer.py b/test/functional/util/dummy_killer.py new file mode 100644 index 0000000..0a052fb --- /dev/null +++ b/test/functional/util/dummy_killer.py @@ -0,0 +1,30 @@ +import signal +import os +import atexit +import tempfile + +def setup_killer(server, method = None): + def default_method(): + server.server_close() + + if method is None: + method = default_method + + def alarm_handler(signum, frame): + method() + + signal.signal(signal.SIGALRM, alarm_handler) + signal.signal(signal.SIGTERM, alarm_handler) + signal.alarm(120) + + +def write_pid(path): + with tempfile.NamedTemporaryFile(mode='w', delete=False) as f: + f.write(str(os.getpid())) + f.close() + os.rename(f.name, path) + + def cleanup(): + os.remove(path) + + atexit.register(cleanup) |