Polling repeatedly checks a resource or condition at a configured interval. For a changing image file, compare its current modification time with the previous value, report whether it changed, then pause before checking again. section 10.4.2
A reusable file-polling loop typically:
- Stores the path and initializes the previous modification time. section 10.4.2
- Reads the current modification time and compares it with the stored value. section 10.4.2
- Updates the stored value, handles new data when a change is detected, and sleeps for the polling interval. section 10.4.5
Polling a live camera image
A camera saves frames to robo_stream.jpg at 30 frames per second. A FileWatcher polls the file at 60 checks per second, producing alternating changed and unchanged results as new frames arrive. A Tornado handler reads changed JPEG images and flushes them to a browser as Motion JPEG. section 10.4.2 section 10.4.5
class FileWatcher:
def __init__(self, path):
self.path = path
self.last_mtime = None
def has_changed(self):
mtime = getmtime(self.path)
last_mtime = self.last_mtime
self.last_mtime = mtime
return (mtime != last_mtime)
Browse the FileWatcher implementation that compares modification times and returns a change flag. section 10.4.2








