def read_events(self, timeout=None):
        if timeout is not None:
            rs, ws, xs = select.select([self.__fd], [], [], timeout)
            if self.__fd not in rs:
                return []

        while True:
            try:
                s = os.read(self.__fd, 1024)
                break
            except OSError as e:
                if e.errno != errno.EINTR:
                    raise FSMonitorOSError(*e.args)

        events = []
        if not module_loaded:
            return events

        for wd, mask, cookie, name in parse_events(s):
            with self.__lock:
                watch = self.__wd_to_watch.get(wd)
            if watch is not None and watch.enabled:
                bit = 1
                while bit < 0x10000:
                    if mask & bit:
                        action = action_map.get(bit)
                        if action is not None and (action & watch.flags):
                            events.append(FSEvent(watch, action, name))
                    bit <<= 1
                if mask & IN_IGNORED:
                    with self.__lock:
                        try:
                            del self.__wd_to_watch[wd]
                        except __HOLE__:
                            pass
        return events
dataset/ETHPy150Open shaurz/fsmonitor/fsmonitor/linux.py/FSMonitor.read_events