ho fatto un bel pò di modifiche:
codice:
import sys
import time
import shutil
from watchdog.events import FileSystemEventHandler
from utils import get_first_file

class MonitorFile(FileSystemEventHandler):

    def crea_semaforo(self):
        file = get_first_file('./csv')

        if file != 'ND':
            shutil.move('./csv/' + file, './test_file/' + file)
            time.sleep(2)

            f = open('./test_semaforo/semaforo', "a")
            f.write("")
            f.close()
        else:
            exit() --> FUNZIONA

    def on_deleted(self, event):
        if event.src_path == './test_semaforo\semaforo':
            print('CANCELLATO')
            file = get_first_file('./csv')
            print(file)
            if file != 'ND':
                self.crea_semaforo()
            else:
                exit() --> NON FUNZIONA
e lancio tutto così:
codice:
if __name__ == '__main__':
    # fatture()

    event_handler = MonitorFile()
    event_handler.crea_semaforo()

    observer = Observer()
    observer.schedule(event_handler, path='./test_semaforo', recursive=False)
    observer.start()

    try:
        while (True):
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
        observer.join()
funziona tutto tranne l'exit.
cioè, quando arrivo che file è uguale ad ND, lui deve uscire proprio dal programma.
perchè la procedura è finita, ed è inutile che rimane un processo attivo.
però rimane tutto attivo.