Python Watchdog Not Working

I am running a Python source node that uses Watchdog to verify that a file has been added to my downloads folder.

My code works fine in Jupyter Notebook but it seems that the Watchdog part of my code is just getting skipped entirely in the Python Source node.

Is there a known issue with Watchdog and watching a directory from inside of KNIME?

Thanks!

Code Snippet:

from watchdog.observers import Observer
from watchdog.events import RegexMatchingEventHandler
class ExampleHandler(RegexMatchingEventHandler):
def on_modified(self, event):
downloads = event.src_path
if len(downloads) >= 1:
observer.stop()
browser.quit()

if name == “main”:
pattern = ‘.311_4_..zip’
event_handler = ExampleHandler(regexes=[pattern], ignore_directories=True)
observer = Observer()
path = r"C:\Users\Downloads"
observer.schedule(event_handler, path, recursive=True)
observer.start()
observer.join()

Hi @TardisPilot,

You need to remove this line from the script:

KNIME’s Python nodes do not execute the user-provided script directly as the Python main module but rather via Python’s eval function.

Marcel

5 Likes

@MarcelW

Thank you so much for the reply! I had to fix some unseen spacing issues in my overall code but it’s working perfectly! Thank you again!

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.