Open bostrt opened 2 months ago
For what its worth, I workaround this like using a var to track if signal has been received:
from concurrent.futures import ThreadPoolExecutor
import signal
import threading
def main():
with ThreadPoolExecutor(max_workers=2) as executor:
exit_signal = threading.Event()
def __exit(signal, frame):
exit_signal.set()
signal.signal(signal.SIGTERM, __exit)
while True:
if exit_signal.is_set():
executor.shutdown(wait=True, cancel_futures=True)
break
executor.submit(lambda: 1 + 1)
if __name__ == "__main__":
main()
Bug report
Bug description:
When running the code below and sending a SIGTERM to the process results in what looks like a deadlock on the
ThreadPoolExecutor._shutdown_lock
. I guess the issue is that the SIGTERM is being handled in main thread while in thesubmit
function where the_shutdown_lock
is already locked. When I try callingshutdown
inside the signal handler it waits forever.TBH I'm not sure if this is a bug or expected behavior but I wanted to file this anyways. Thanks!
AFTER sending SIGTERM to the process, this is what
pystack
shows:CPython versions tested on:
3.12
Operating systems tested on:
Linux