本文整理匯總了Python中select.EPOLLPRI屬性的典型用法代碼示例。如果您正苦於以下問題:Python select.EPOLLPRI屬性的具體用法?Python select.EPOLLPRI怎麽用?Python select.EPOLLPRI使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類select
的用法示例。
在下文中一共展示了select.EPOLLPRI屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _poll_queue_event
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLPRI [as 別名]
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())
示例2: _run
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLPRI [as 別名]
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())
示例3: _getflags
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLPRI [as 別名]
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.
示例4: _poll_queue_register_pin
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLPRI [as 別名]
def _poll_queue_register_pin(self, pin):
''' Pin responds to fileno(), so it's pollable. '''
self._poll_queue.register(pin, (select.EPOLLPRI | select.EPOLLET))
示例5: run
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLPRI [as 別名]
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()
示例6: __init__
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLPRI [as 別名]
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))
示例7: poll
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLPRI [as 別名]
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)