import select import signal import threading import time import os def handle_signal_slowly(a, b): time.sleep(1) def send_signal(): time.sleep(0.5) os.kill(os.getpid(), signal.SIGTERM) read_end, write_end = os.pipe() rlist, wlist, xlist = select.select([read_end], [], [], 1) print(rlist) signal.signal(signal.SIGTERM, handle_signal_slowly) thread = threading.Thread(target=send_signal) thread.start() rlist, wlist, xlist = select.select([read_end], [], [], 1) print(rlist)