zpoller = zmq.Poller() zpoller.register(ifd, zmq.POLLIN) zpoller.register(z.inbox, zmq.POLLIN) def handle_modified(peer, name, data, *args, **kwargs): global iwd global ifd print(data, name, "watchdir" in data.keys()) if "watchdir" in data.keys(): logger.debug("watchdir modified to {1} by {0}".format(peer, data)) # stop current watch i.inotify_rm_watch(ifd, iwd) # start new watch iwd = i.inotify_add_watch( ifd, z.get_value('watchdir'), pyinotify.IN_DELETE ) z.on_modified = handle_modified def handle_inotify(): buf = array.array('i', [0]) if fcntl.ioctl(ifd, termios.FIONREAD, buf, 1) == -1: # get length of buffer logger.error('some ioctl -1 error') running = False return length = buf[0] # read data # todo we should loop over the data! recv = os.read(ifd, length) logger.debug("handle_inotify: recveived length {0}".format(len(recv))) rwd, evmask, cookie, data_length = struct.unpack('iIII', recv[0:16]) if rwd != iwd: logger.debug("watch descriptor doesn't match: %d is not %d" %(rwd, iwd))