I’m using MacFSEvents, a Python library that monitors a directory for changes on Mac OS X, like so:
# from http://pypi.python.org/packages/source/M/MacFSEvents/
from fsevents import Observer
from fsevents import Stream
observer = Observer()
def callback(event):
print event.name
stream = Stream(callback, '.', file_events=True)
observer.schedule(stream)
observer.start()
When I run this script in the Terminal, hitting Ctrl-C doesn’t exit the program — the only way I can find to kill it is with ‘kill’ in a separate window, or with Activity Monitor, etc.
Any ideas on how to make such a program killable by Ctrl-C?
An alternative is to look for
KeyboardInterruptand stop the observer manually (as an alternative toobserver.run()):