Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python event start from file funcion

from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

class WatchPendingHandler(FileSystemEventHandler):
    ''' Run a handler for every file added to the pending dir

    This class also handles what I call a bug in the watchdog module
    which means that you can get more than one call per real event
    in the watched dir tree.
    '''

    def __init__(self):
        super(WatchPendingHandler, self).__init__()
        # wip is used to avoid bug in watchdog which means multiple calls
        # for one real event.
        # For reference: https://github.com/gorakhargosh/watchdog/issues/346
        self.wip = []

    def on_created(self, event):
        path = event.src_path
        if event.is_directory:
            logging.debug('WatchPendingHandler() New dir created in pending dir: {}'.format(path))
            return
        if path in self.wip:
            logging.debug('WatchPendingHandler() Dup created event for %s', path)
            return
        self.wip.append(path)
        logging.debug('WatchPendingHandler() New file created in pending dir: {}'.format(path))
        HandleNewlyCreated(path)

    def on_moved(self, event):
        logging.debug('WatchPendingHandler() %s has been moved', event.src_path)
        with contextlib.suppress(ValueError):
            self.wip.remove(event.src_path)

    def on_deleted(self, event):
        path = event.src_path
        logging.debug('WatchPendingHandler() %s has been deleted', path)
        with contextlib.suppress(ValueError):
            self.wip.remove(path)

observer = Observer()
observer.schedule(WatchPendingHandler(), DIR_PENDING, recursive=True)
observer.start()
logging.info('Watching %s', DIR_PENDING)
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    observer.stop()
observer.join()
Comment

PREVIOUS NEXT
Code Example
Python :: how many orders has customer made database python 
Python :: holding a function to the code in python 
Python :: Kernel Ridge et Hyperparameter cross validation sklearn 
Python :: check if inf pandas dataframe 
Shell :: classic confinement requires snaps under /snap or symlink from /snap to /var/lib/snapd/snap 
Shell :: chrome inspect devices 
Shell :: add-apt-repository command not found 
Shell :: amazon linux 2 install stress 
Shell :: react-scripts is not recognized as an internal command windows 
Shell :: uninstall node js and npm ubuntu 
Shell :: ubuntu pip3 
Shell :: how to remove node_modules from git 
Shell :: install git-lfs ubuntu 18.04 
Shell :: update node version debian 
Shell :: date linux format yyyymmdd 
Shell :: how to add docker to sudo group 
Shell :: git pull master discard local changes 
Shell :: sqlite3 install ubuntu 
Shell :: curl not found 
Shell :: npm install --no-audit --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed. 
Shell :: curl ip address 
Shell :: kill port in linux 
Shell :: Failed to restart mongodb.service: Unit mongodb.service is masked. 
Shell :: download pip for python in linux 
Shell :: set java version for ubuntu 20.04 
Shell :: (node:14140) UnhandledPromiseRejectionWarning: Error: FFmpeg/avconv not found! 
Shell :: rm is not recognized as internal command 
Shell :: uninstall flutter from snap 
Shell :: git show graph command line 
Shell :: necessary tools to install on kali linux WSL 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =