Documentation Index
Fetch the complete documentation index at: https://mintlify.com/skyrobot804/node_v1/llms.txt
Use this file to discover all available pages before exploring further.
ImageWatcher uses the watchdog library to monitor a directory for new FITS files using OS-native filesystem events — inotify on Linux, FSEvents on macOS, and kqueue on BSD/macOS. Because it registers with the operating system’s event subsystem rather than polling the directory on a timer, it incurs essentially zero CPU overhead while idle and detects new files with sub-second latency. A configurable debounce window lets partially written files finish before the callback fires.
Constructor
ImageWatcher instance but does not start file monitoring. Call start() to activate the OS observer thread.
Absolute or relative path to the directory to monitor. Must be an existing directory at the time
start() is called (checked with os.path.isdir). Subdirectories are not watched — monitoring is non-recursive.Callable invoked once per stable new FITS file. Receives a single dict argument; see Callback Event Dict for the shape. Exceptions raised inside the callback are caught and logged at
ERROR level — they do not stop the watcher.Time in seconds to wait after the last filesystem event for a given path before invoking the callback. Any new event for the same path during the debounce window resets the timer. Increase this value for slow storage (e.g. NFS mounts or USB drives) where large FITS files take longer to finish writing.
start()
watch_path for filesystem events. If watch_path does not exist at call time, the error is logged and the method returns without raising — the watcher is left in a non-running state.
The internal watchdog.observers.Observer thread is set as a daemon thread so it does not block process exit if stop() is not called explicitly.
stop()
- Sets
_running = Falseso any pending timer callbacks that fire after this point are no-ops. - Cancels all pending debounce
threading.Timerobjects and clears the timers dict. - Calls
observer.stop()to signal the watchdog thread to exit. - Calls
observer.join()to wait for the thread to finish cleanly.
stop() returns, no further callbacks will be invoked. It is safe to call stop() more than once.
Callback Event Dict
The single argument passed tocallback on each stable FITS detection.
Absolute path to the detected FITS file, e.g.
"/mnt/seestar/image_20250601_023412.fits".FITS primary HDU header as a plain Python dict, with
COMMENT and HISTORY keywords stripped and string values whitespace-stripped. Returns {} if the header could not be read (e.g. corrupt file or permission error). Typical keys include OBJECT, EXPTIME, DATE-OBS, RA, DEC, IMAGETYP, FILTER.File size in kilobytes at the moment the callback fires, from
os.path.getsize(path) / 1024.0.File Types
Only files with extensions.fits or .fit (case-insensitive) trigger debounce timers and ultimately the callback. All other files created or moved into watch_path are silently ignored by the _schedule() filter.
Debounce Behavior
The watcher handles two watchdog event types:on_created— fires when a new file is created in the watched directory.on_moved— fires when a file is renamed or moved into the watched directory (e.g. an atomicrename(tmp, final.fits)completion).
_schedule(path), which:
- Cancels any existing
threading.Timerfor that path. - Starts a new timer for
debounce_delayseconds. - When the timer expires without being reset,
_fire(path)is called.
_fire() verifies the file still exists (os.path.isfile), reads the FITS header, measures the file size, and invokes the callback. This means the callback always receives a complete, stable file regardless of how long the camera took to finish writing it.
