title: Watchdog in Python to look for filesystem changes not working (freezing)
body: <p>I'm working on a Python script to monitor a folder to check whether a new *.JPG file is added to that folder and then do some tasks. The code is working, but after some time after being started, it seems to be freezing and stops working even a new file is added to the folder.</p>
  <p>Here is the code:</p>
  <pre><code># -*- encoding: iso-8859-1 -*-
  import time
  import os
  import flickrapi
  import shutil
  from PIL import Image
  from PIL.ExifTags import TAGS
  from watchdog.observers import Observer
  from watchdog.events import PatternMatchingEventHandler
  
  if __name__ == &quot;__main__&quot;:
      patterns = [&quot;*.jpg&quot;]
      ignore_patterns = None
      ignore_directories = False
      case_sensitive = False
      my_event_handler = PatternMatchingEventHandler(patterns, ignore_patterns, ignore_directories, case_sensitive)
  
  def get_exif(img):
      ''' Extract Exif data from image '''
  
  def copyright(img):
      # get the path of img and create an output filename
      tail = os.path.split(img)[1]
      filename = 'wtmk_' + tail[:-3] + 'png'
  
      #open the base image and get it's dimensions
      while True:
          try:
              # read file
              base_image = Image.open(img)
              bw, bh = base_image.size
              bw2 = bw // 2
              break
          except IOError:
              time.sleep(5)
              
         ''' Add watermark to image '''
      
      return waterMarkedImage
  
  def on_created(event):
      # Add the watermark
      file = copyright(event.src_path)
  
      # extract EXIF data
      exifdata = get_exif(event.src_path)
   
      ''' Send the image to FLICKR '''
  
  # Create and start the observer
  my_event_handler.on_created = on_created
  
  path = &quot;c:\\temp&quot;
  go_recursively = False
  my_observer = Observer()
  my_observer.schedule(my_event_handler, path, recursive=go_recursively)
  my_observer.start()
  
  try:
      while True:
              time.sleep(5)
  except KeyboardInterrupt:
          my_observer.stop()
          my_observer.join()
  </code></pre>
  <p>I'm running the above code using Python 3.8 on a Windows 10 machine. Any help would be awesome!</p>
  <p>Marcio</p>