我认为看守者库是在这里使用的更好的东西,就像火葬者所提到的那样。我已使用它如下监视新文件的文件夹:
import time from watchdog.observers import Observerfrom watchdog.events import FileSystemEventHandlerclass ExampleHandler(FileSystemEventHandler): def on_created(self, event): # when file is created # do something, eg. call your function to process the image print "Got event for file %s" % event.src_pathobserver = Observer()event_handler = ExampleHandler() # create event handler# set observer to use created handler in directoryobserver.schedule(event_handler, path='/folder/to/watch')observer.start()# sleep until keyboard interrupt, then stop + rejoin the observertry: while True: time.sleep(1)except KeyboardInterrupt: observer.stop()observer.join()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)