def handle_read(self): try: buf = self.recv(timerfd.bufsize) except OSError as e: if e.args[0] in (errno.EINTR, errno.EAGAIN): return raise if buf: count = timerfd.unpack(buf) self.handle_expire(count) else: self.close()
import timerfd import select import os timer = timerfd.timerfd(timerfd.CLOCK_MONOTONIC, timerfd.TFD_NONBLOCK) timer.settime(0, value=0.5, interval=0.5) print(timer.gettime()) timer.settime(0, value=1.2, interval=0.15) print(timer.gettime()) epoll = select.epoll() epoll.register(timer.fileno(), select.EPOLLIN) while True: for fd, mask in epoll.poll(-1): print(timer.gettime()) print(timerfd.unpack(os.read(fd, 8)))