

# https://www.globalsino.com/ICs/
# The observer runs in the background and pass the value of obtained events to a/another function call

import time
from watchdog.observers import Observer
import sys
from os.path import exists
from watchdog.events import FileSystemEventHandler
from page4853simpleCal import SimpleCal

def on_created(event):
    if event.src_path !=None:
        print(event.src_path)
        time.sleep(1)
        exec(open(r"C:\GlobalSino2\ICs\page4853WatchdogMonitorFileAndCallAnotherFile.py",  encoding = 'utf-8').read())
        
def run_observer():
    path = r'C:\0Python\images'
    observer = Observer()
    observer.schedule(event_handler, path, recursive=True)
    observer.start()
    while True:
        time.sleep(1)
        SimpleCal() # This function exists and can be run
        SimpleCal2() # Error test: This file/function does not exist
        
if __name__ == "__main__":
    event_handler = FileSystemEventHandler()
    event_handler.on_created=on_created
    run_observer()
    
    
