kill threads with subprocesses on exit

This commit is contained in:
iLLiCiTiT 2019-10-23 17:34:11 +02:00
parent 565c43971c
commit bfa61e2e98
3 changed files with 15 additions and 2 deletions

View file

@ -3,6 +3,7 @@ import sys
import signal
import socket
import argparse
import atexit
import time
from urllib.parse import urlparse
@ -153,6 +154,18 @@ def main_loop(ftrack_url, username, api_key, event_paths):
printed_ftrack_error = False
printed_mongo_error = False
def on_exit():
if processor_thread is not None:
processor_thread.stop()
processor_thread.join()
processor_thread = None
if storer_thread is not None:
storer_thread.stop()
storer_thread.join()
storer_thread = None
atexit.register(on_exit)
# Main loop
while True:
# Check if accessible Ftrack and Mongo url

View file

@ -46,4 +46,4 @@ if __name__ == "__main__":
if hasattr(signal, "SIGKILL"):
signal.signal(signal.SIGKILL, signal_handler)
main(sys.argv)
sys.exit(main(sys.argv))

View file

@ -105,4 +105,4 @@ if __name__ == "__main__":
if hasattr(signal, "SIGKILL"):
signal.signal(signal.SIGKILL, signal_handler)
main(sys.argv)
sys.exit(main(sys.argv))