Python select.EPOLLPRI Examples
The following are 7
code examples of select.EPOLLPRI().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
select
, or try the search function
.
Example #1
Source File: gpio.py From python-sysfs-gpio with MIT License | 6 votes |
def _poll_queue_event(self, events): """ EPoll event callback """ for fd, event in events: if not (event & (select.EPOLLPRI | select.EPOLLET)): continue try: values = self._allocated_pins.itervalues() except AttributeError: values = self._allocated_pins.values() for pin in values: if pin.fileno() == fd: pin.changed(pin.read())
Example #2
Source File: gpio.py From respeaker_python_library with Apache License 2.0 | 5 votes |
def _run(self): while self._running: events = self._poll.poll(EPOLL_TIMEOUT) for fd, event in events: if not (event & (select.EPOLLPRI | select.EPOLLET)): continue self.changed(self.read())
Example #3
Source File: asyncio.py From pycopia with Apache License 2.0 | 5 votes |
def _getflags(self, aiobj): flags = 0 if aiobj.readable(): flags = EPOLLIN if aiobj.writable(): flags |= EPOLLOUT if aiobj.priority(): flags |= EPOLLPRI return flags # A poller is itself selectable so may be nested in another Poll # instance. Therefore, supports the async interface itself.
Example #4
Source File: gpio.py From python-sysfs-gpio with MIT License | 5 votes |
def _poll_queue_register_pin(self, pin): ''' Pin responds to fileno(), so it's pollable. ''' self._poll_queue.register(pin, (select.EPOLLPRI | select.EPOLLET))
Example #5
Source File: key_event_management.py From openrazer with GNU General Public License v2.0 | 5 votes |
def run(self): """ Main event loop """ # Create dict of Event File Descriptor: Event File Object event_file_map = {event_file.fileno(): event_file for event_file in self.open_event_files} # Create epoll object poll_object = select.epoll() # Register files with select for event_fd in event_file_map.keys(): poll_object.register(event_fd, select.EPOLLIN | select.EPOLLPRI) # Loop while not self._shutdown: # epoll is nice but it wasn't getting events properly :( try: # Cheap hack until i merged new code if self._use_epoll: self._poll_epoll(poll_object, event_file_map) else: self._poll_read() except (IOError, OSError): # Basically if there's an error, most likely device has been removed then it'll get deleted properly pass time.sleep(SPIN_SLEEP) # Unbind files and close them for event_fd, event_file in event_file_map.items(): poll_object.unregister(event_fd) event_file.close() poll_object.close()
Example #6
Source File: gpio.py From respeaker_python_library with Apache License 2.0 | 4 votes |
def __init__(self, number, direction=INPUT, callback=None, edge=None, active_low=0): """ @type number: int @param number: The pin number @type direction: int @param direction: Pin direction, enumerated by C{Direction} @type callback: callable @param callback: Method be called when pin changes state @type edge: int @param edge: The edge transition that triggers callback, enumerated by C{Edge} @type active_low: int @param active_low: Indicator of whether this pin uses inverted logic for HIGH-LOW transitions. """ self._number = number self._direction = direction self._callback = callback self._active_low = active_low if not os.path.isfile(self._sysfs_gpio_value_path()): with open(SYSFS_EXPORT_PATH, 'w') as export: export.write('%d' % number) else: Logger.debug("SysfsGPIO: Pin %d already exported" % number) self._fd = open(self._sysfs_gpio_value_path(), 'r+') if callback and not edge: raise Exception('You must supply a edge to trigger callback on') with open(self._sysfs_gpio_direction_path(), 'w') as fsdir: fsdir.write(direction) if edge: with open(self._sysfs_gpio_edge_path(), 'w') as fsedge: fsedge.write(edge) self._poll = select.epoll() self._poll.register(self, (select.EPOLLPRI | select.EPOLLET)) self.thread = Thread(target=self._run) self.thread.daemon = True self._running = True self.thread.start() if active_low: if active_low not in ACTIVE_LOW_MODES: raise Exception('You must supply a value for active_low which is either 0 or 1.') with open(self._sysfs_gpio_active_low_path(), 'w') as fsactive_low: fsactive_low.write(str(active_low))
Example #7
Source File: asyncio.py From pycopia with Apache License 2.0 | 4 votes |
def poll(self, timeout=-1.0): while 1: try: rl = self.pollster.poll(timeout) except IOError as why: if why.errno == EINTR: self._run_idle() continue else: raise else: break for fd, flags in rl: try: hobj = self.smap[fd] except KeyError: # this should never happen, but let's be safe. continue if hobj is None: # signals simple callback self._fd_callbacks[fd]() continue try: if (flags & EPOLLERR): hobj.error_handler() continue if (flags & POLLNVAL): self.unregister_fd(fd) continue if (flags & EPOLLPRI): hobj.pri_handler() if (flags & EPOLLIN): hobj.read_handler() if (flags & EPOLLOUT): hobj.write_handler() if (flags & EPOLLHUP): hobj.hangup_handler() except UnregisterNow as unr: self.unregister(unr.obj) except UnregisterFDNow as unr: self.unregister_fd(unr.filedescriptor) except (KeyboardInterrupt, SystemExit): raise except: ex, val, tb = sys.exc_info() hobj.exception_handler(ex, val, tb)