Pagina 2 di 2 primaprima 1 2
Visualizzazione dei risultati da 11 a 12 su 12
  1. #11
    Utente di HTML.it L'avatar di clasku
    Registrato dal
    Aug 2006
    Messaggi
    3,197
    Usa sys.exit() invece di exit()

  2. #12
    ciao!

    ho provato anche con sys.exit:
    codice:
    import sys
    import time
    import shutil
    from watchdog.events import FileSystemEventHandler
    from watchdog.observers import Observer
    from utils import get_first_file, count_csv
    
    class MonitorFile(FileSystemEventHandler):
    
        def __init__(self):
            self.dir_semaforo = './test_semaforo'
            self.file_semaforo = './test_semaforo/semaforo'
            self.file_canc = './test_semaforo\semaforo'
            self.dir_to_move = './test_file/'
            self.dir_csv = './csv'
            self.observer = Observer()
    
        def crea_semaforo(self):
            if count_csv(self.dir_csv) > 0:
                file = get_first_file(self.dir_csv)
    
                shutil.move('./csv/' + file, self.dir_to_move + file)
                time.sleep(1)
    
                f = open(self.file_semaforo, "a")
                f.write("")
                f.close()
            else:
                sys.exit("ESCO")
    
        def run_observer(self):
            self.observer.schedule(self, path=self.dir_semaforo, recursive=False)
            self.observer.start()
    
            try:
                while (True):
                    time.sleep(1)
            except (KeyboardInterrupt, SystemExit):
                self.observer.stop()
                time.sleep(1)
    
            self.observer.join()
    
        def on_deleted(self, event):
            if event.src_path == self.file_canc:
                if count_csv(self.dir_csv) > 0:
                    self.crea_semaforo()
                else:
                    self.observer.stop()
                    print(count_csv(self.dir_csv)) # STAMPA ZERO -- CORRETTO
                    print("DA USCIRE") # STAMPA IL PRINT -- CORRETTO
                    sys.exit("ESCO") # NON STAMPA NULLA -- RIMASE APPESO
    ti ho messo nei commenti il comportamente che ha.
    in pratica il processo rimane appeso.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.