Guest User

Untitled

a guest
Jun 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. class Poller():
  2. def __init__(self, q, killswitch):
  3. self.q = q
  4. self.killswitch = killswitch
  5. self.path = conf.FIFO_PATH
  6. self.dir = conf.FIFO_DIRECTORY
  7.  
  8. if not os.path.exists(self.dir):
  9. os.mkdir(self.dir)
  10.  
  11. if not os.path.exists(self.path):
  12. new_file(self.path)
  13.  
  14. self.fifo = os.open(self.path, os.O_RDONLY | os.O_NONBLOCK)
  15. self.poller = select.poll()
  16. self.poller.register(self.fifo, select.POLLIN)
  17.  
  18. def listen(self):
  19. while not self.killswitch.isSet():
  20. p = self.poller.poll()
  21. msg = os.read(p[0][0], 50)
  22. if len(msg):
  23. ev = Event(msg, self.q)
  24. ev.signal()
Add Comment
Please, Sign In to add comment