From 300817fe704a1f63e7a5e7671024b8b6895ce95c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 14 Dec 2018 16:35:08 +0100 Subject: [PATCH] Terminate process with stacktrace if PipeReaderThread fails --- pipe_io_server.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pipe_io_server.py b/pipe_io_server.py index 8659583..3141c24 100644 --- a/pipe_io_server.py +++ b/pipe_io_server.py @@ -1,10 +1,12 @@ from threading import Thread from queue import Queue -from os import mkfifo, remove +from os import mkfifo, remove, getpid, kill from os.path import exists, join +from signal import SIGTERM from secrets import token_urlsafe from collections import namedtuple from abc import ABC, abstractmethod +from traceback import print_exc class PipeWriterThread(Thread): @@ -43,7 +45,11 @@ class PipeReaderThread(Thread): message = pipe.read() if message == self._stop_sequence: break - self._message_handler(message) + try: + self._message_handler(message) + except: + print_exc() + kill(getpid(), SIGTERM) def stop(self): with open(self._pipe_path, 'wb') as pipe: