def run(self): pool = AppKit.NSAutoreleasePool.alloc().init() self._run_loop = CFRunLoopGetCurrent() FSEventStreamScheduleWithRunLoop(self._stream_ref, self._run_loop, kCFRunLoopDefaultMode) if not FSEventStreamStart(self._stream_ref): FSEventStreamInvalidate(self._stream_ref) FSEventStreamRelease(self._stream_ref) raise IOError('FSEvents. Could not start stream.') CFRunLoopRun() FSEventStreamStop(self._stream_ref) FSEventStreamInvalidate(self._stream_ref) FSEventStreamRelease(self._stream_ref) del pool self._queue.put(None)
def run(self): # Necessary because we're using PyObjC in a thread other than the main # thread. self.auto_release_pool = NSAutoreleasePool.alloc().init() # Setup. Ensure that this isn't interleaved with any other thread, so # that the DB setup continues as expected. self.lock.acquire() FSMonitor.setup(self) self.lock.release() # Set up a callback to a function that process the queues frequently. CFRunLoopAddTimer( CFRunLoopGetCurrent(), CFRunLoopTimerCreate(None, CFAbsoluteTimeGetCurrent(), 0.5, 0, 0, self.__process_queues, None), kCFRunLoopDefaultMode) # Start the run loop. CFRunLoopRun()