Python select.EPOLLIN Examples
The following are 30
code examples of select.EPOLLIN().
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: test_epoll.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_fromfd(self): server, client = self._connected_pair() ep = select.epoll(2) ep2 = select.epoll.fromfd(ep.fileno()) ep2.register(server.fileno(), select.EPOLLIN | select.EPOLLOUT) ep2.register(client.fileno(), select.EPOLLIN | select.EPOLLOUT) events = ep.poll(1, 4) events2 = ep2.poll(0.9, 4) self.assertEqual(len(events), 2) self.assertEqual(len(events2), 2) ep.close() try: ep2.poll(1, 4) except OSError as e: self.assertEqual(e.args[0], errno.EBADF, e) else: self.fail("epoll on closed fd didn't raise EBADF")
Example #2
Source File: dnx_parent_classes.py From dnxfirewall-cmd with GNU General Public License v3.0 | 6 votes |
def __register(self, listener, intf=None): '''will register interface with listener. requires subclass property for listener_sock returning valid socket object. once registration is complete the thread will exit.''' # this is being defined here the listener will be able to correlate socket back to interface and send in. _intf = intf if intf else self._intf self._Log.debug(f'{self._name} started interface registration for {_intf}') interface.wait_for_interface(interface=_intf) self._intf_ip = interface.wait_for_ip(interface=_intf) l_sock = self.listener_sock listener.__registered_socks[l_sock.fileno()] = L_SOCK(l_sock, _intf) # TODO: make a namedtuple # TODO: if we dont re register, and im pretty sure i got rid of that, we shouldnt need to track the interface # anymore yea? the fd and socket object is all we need, unless we need to get the source ip address. OH. does the # dns proxy need to grab its interface ip for sending to the client? i dont think so, right? it jsut needs to # spoof the original destination. listener.__epoll.register(l_sock.fileno(), select.EPOLLIN) self._Log.notice(f'{self._name} | {_intf} registered.')
Example #3
Source File: test_epoll.py From BinderFilter with MIT License | 6 votes |
def test_fromfd(self): server, client = self._connected_pair() ep = select.epoll(2) ep2 = select.epoll.fromfd(ep.fileno()) ep2.register(server.fileno(), select.EPOLLIN | select.EPOLLOUT) ep2.register(client.fileno(), select.EPOLLIN | select.EPOLLOUT) events = ep.poll(1, 4) events2 = ep2.poll(0.9, 4) self.assertEqual(len(events), 2) self.assertEqual(len(events2), 2) ep.close() try: ep2.poll(1, 4) except IOError, e: self.assertEqual(e.args[0], errno.EBADF, e)
Example #4
Source File: test_epoll.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_close(self): open_file = open(__file__, "rb") self.addCleanup(open_file.close) fd = open_file.fileno() epoll = select.epoll() # test fileno() method and closed attribute self.assertIsInstance(epoll.fileno(), int) self.assertFalse(epoll.closed) # test close() epoll.close() self.assertTrue(epoll.closed) self.assertRaises(ValueError, epoll.fileno) # close() can be called more than once epoll.close() # operations must fail with ValueError("I/O operation on closed ...") self.assertRaises(ValueError, epoll.modify, fd, select.EPOLLIN) self.assertRaises(ValueError, epoll.poll, 1.0) self.assertRaises(ValueError, epoll.register, fd, select.EPOLLIN) self.assertRaises(ValueError, epoll.unregister, fd)
Example #5
Source File: test_epoll.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_fromfd(self): server, client = self._connected_pair() ep = select.epoll(2) ep2 = select.epoll.fromfd(ep.fileno()) ep2.register(server.fileno(), select.EPOLLIN | select.EPOLLOUT) ep2.register(client.fileno(), select.EPOLLIN | select.EPOLLOUT) events = ep.poll(1, 4) events2 = ep2.poll(0.9, 4) self.assertEqual(len(events), 2) self.assertEqual(len(events2), 2) ep.close() try: ep2.poll(1, 4) except IOError, e: self.assertEqual(e.args[0], errno.EBADF, e)
Example #6
Source File: test_epoll.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_fromfd(self): server, client = self._connected_pair() ep = select.epoll(2) ep2 = select.epoll.fromfd(ep.fileno()) ep2.register(server.fileno(), select.EPOLLIN | select.EPOLLOUT) ep2.register(client.fileno(), select.EPOLLIN | select.EPOLLOUT) events = ep.poll(1, 4) events2 = ep2.poll(0.9, 4) self.assertEqual(len(events), 2) self.assertEqual(len(events2), 2) ep.close() try: ep2.poll(1, 4) except OSError as e: self.assertEqual(e.args[0], errno.EBADF, e) else: self.fail("epoll on closed fd didn't raise EBADF")
Example #7
Source File: test_epoll.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_close(self): open_file = open(__file__, "rb") self.addCleanup(open_file.close) fd = open_file.fileno() epoll = select.epoll() # test fileno() method and closed attribute self.assertIsInstance(epoll.fileno(), int) self.assertFalse(epoll.closed) # test close() epoll.close() self.assertTrue(epoll.closed) self.assertRaises(ValueError, epoll.fileno) # close() can be called more than once epoll.close() # operations must fail with ValueError("I/O operation on closed ...") self.assertRaises(ValueError, epoll.modify, fd, select.EPOLLIN) self.assertRaises(ValueError, epoll.poll, 1.0) self.assertRaises(ValueError, epoll.register, fd, select.EPOLLIN) self.assertRaises(ValueError, epoll.unregister, fd)
Example #8
Source File: test_epoll.py From oss-ftp with MIT License | 6 votes |
def test_fromfd(self): server, client = self._connected_pair() ep = select.epoll(2) ep2 = select.epoll.fromfd(ep.fileno()) ep2.register(server.fileno(), select.EPOLLIN | select.EPOLLOUT) ep2.register(client.fileno(), select.EPOLLIN | select.EPOLLOUT) events = ep.poll(1, 4) events2 = ep2.poll(0.9, 4) self.assertEqual(len(events), 2) self.assertEqual(len(events2), 2) ep.close() try: ep2.poll(1, 4) except IOError, e: self.assertEqual(e.args[0], errno.EBADF, e)
Example #9
Source File: test_epoll.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_add(self): server, client = self._connected_pair() ep = select.epoll(2) try: ep.register(server.fileno(), select.EPOLLIN | select.EPOLLOUT) ep.register(client.fileno(), select.EPOLLIN | select.EPOLLOUT) finally: ep.close() # adding by object w/ fileno works, too. ep = select.epoll(2) try: ep.register(server, select.EPOLLIN | select.EPOLLOUT) ep.register(client, select.EPOLLIN | select.EPOLLOUT) finally: ep.close() ep = select.epoll(2) try: # TypeError: argument must be an int, or have a fileno() method. self.assertRaises(TypeError, ep.register, object(), select.EPOLLIN | select.EPOLLOUT) self.assertRaises(TypeError, ep.register, None, select.EPOLLIN | select.EPOLLOUT) # ValueError: file descriptor cannot be a negative integer (-1) self.assertRaises(ValueError, ep.register, -1, select.EPOLLIN | select.EPOLLOUT) # OSError: [Errno 9] Bad file descriptor self.assertRaises(OSError, ep.register, 10000, select.EPOLLIN | select.EPOLLOUT) # registering twice also raises an exception ep.register(server, select.EPOLLIN | select.EPOLLOUT) self.assertRaises(OSError, ep.register, server, select.EPOLLIN | select.EPOLLOUT) finally: ep.close()
Example #10
Source File: pykms_Selectors.py From py-kms with The Unlicense | 5 votes |
def select(self, timeout=None): if timeout is not None: if timeout <= 0: timeout = 0.0 else: # select.epoll.poll() has a resolution of 1 millisecond # but luckily takes seconds so we don't need a wrapper # like PollSelector. Just for better rounding. timeout = math.ceil(timeout * 1e3) * 1e-3 timeout = float(timeout) else: timeout = -1.0 # epoll.poll() must have a float. # We always want at least 1 to ensure that select can be called # with no file descriptors registered. Otherwise will fail. max_events = max(len(self._fd_to_key), 1) ready = [] fd_events = _syscall_wrapper(self._epoll.poll, True, timeout=timeout, maxevents=max_events) for fd, event_mask in fd_events: events = 0 if event_mask & ~select.EPOLLIN: events |= EVENT_WRITE if event_mask & ~select.EPOLLOUT: events |= EVENT_READ key = self._key_from_fd(fd) if key: ready.append((key, events & key.events)) return ready
Example #11
Source File: recipe-577662.py From code with MIT License | 5 votes |
def registerForEvents(self, asyncSocket, readEvents, writeEvents): fileno = asyncSocket.fileno() eventMask = 0 if (readEvents): eventMask |= select.EPOLLIN if (writeEvents): eventMask |= select.EPOLLOUT self.__poller.register(fileno, eventMask)
Example #12
Source File: selectors.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def register(self, fileobj, events, data=None): key = super(EpollSelector, self).register(fileobj, events, data) events_mask = 0 if events & EVENT_READ: events_mask |= select.EPOLLIN if events & EVENT_WRITE: events_mask |= select.EPOLLOUT _syscall_wrapper(self._epoll.register, False, key.fd, events_mask) return key
Example #13
Source File: selectors.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def select(self, timeout=None): if timeout is not None: if timeout <= 0: timeout = 0.0 else: # select.epoll.poll() has a resolution of 1 millisecond # but luckily takes seconds so we don't need a wrapper # like PollSelector. Just for better rounding. timeout = math.ceil(timeout * 1e3) * 1e-3 timeout = float(timeout) else: timeout = -1.0 # epoll.poll() must have a float. # We always want at least 1 to ensure that select can be called # with no file descriptors registered. Otherwise will fail. max_events = max(len(self._fd_to_key), 1) ready = [] fd_events = _syscall_wrapper(self._epoll.poll, True, timeout=timeout, maxevents=max_events) for fd, event_mask in fd_events: events = 0 if event_mask & ~select.EPOLLIN: events |= EVENT_WRITE if event_mask & ~select.EPOLLOUT: events |= EVENT_READ key = self._key_from_fd(fd) if key: ready.append((key, events & key.events)) return ready
Example #14
Source File: recipe-576759.py From code with MIT License | 5 votes |
def __init__(self, pipe): if isinstance(pipe, int): fd = self._fd = pipe pipe = os.fromfd(pipe) else: fd = self._fd = pipe.fileno() self._poll_in, self._poll_out = epoll(), epoll() self._poll_in.register(fd, EPOLLIN | EPOLLERR | EPOLLHUP) self._poll_out.register(fd, EPOLLOUT | EPOLLERR | EPOLLHUP) self.close = pipe.close self.reads = pipe.read self.writes = pipe.write
Example #15
Source File: test_epoll.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_add(self): server, client = self._connected_pair() ep = select.epoll(2) try: ep.register(server.fileno(), select.EPOLLIN | select.EPOLLOUT) ep.register(client.fileno(), select.EPOLLIN | select.EPOLLOUT) finally: ep.close() # adding by object w/ fileno works, too. ep = select.epoll(2) try: ep.register(server, select.EPOLLIN | select.EPOLLOUT) ep.register(client, select.EPOLLIN | select.EPOLLOUT) finally: ep.close() ep = select.epoll(2) try: # TypeError: argument must be an int, or have a fileno() method. self.assertRaises(TypeError, ep.register, object(), select.EPOLLIN | select.EPOLLOUT) self.assertRaises(TypeError, ep.register, None, select.EPOLLIN | select.EPOLLOUT) # ValueError: file descriptor cannot be a negative integer (-1) self.assertRaises(ValueError, ep.register, -1, select.EPOLLIN | select.EPOLLOUT) # OSError: [Errno 9] Bad file descriptor self.assertRaises(OSError, ep.register, 10000, select.EPOLLIN | select.EPOLLOUT) # registering twice also raises an exception ep.register(server, select.EPOLLIN | select.EPOLLOUT) self.assertRaises(OSError, ep.register, server, select.EPOLLIN | select.EPOLLOUT) finally: ep.close()
Example #16
Source File: selectors.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def select(self, timeout=None): if timeout is None: timeout = -1 elif timeout <= 0: timeout = 0 else: # epoll_wait() has a resolution of 1 millisecond, round away # from zero to wait *at least* timeout seconds. timeout = math.ceil(timeout * 1e3) * 1e-3 # epoll_wait() expects `maxevents` to be greater than zero; # we want to make sure that `select()` can be called when no # FD is registered. max_ev = max(len(self._fd_to_key), 1) ready = [] try: fd_event_list = self._epoll.poll(timeout, max_ev) except InterruptedError: return ready for fd, event in fd_event_list: events = 0 if event & ~select.EPOLLIN: events |= EVENT_WRITE if event & ~select.EPOLLOUT: events |= EVENT_READ key = self._key_from_fd(fd) if key: ready.append((key, events & key.events)) return ready
Example #17
Source File: recipe-577662.py From code with MIT License | 5 votes |
def doPoll(self, block): readyList = self.__poller.poll(-1 if block else 0) for (fd, eventMask) in readyList: readReady = ((eventMask & select.EPOLLIN) != 0) writeReady = ((eventMask & select.EPOLLOUT) != 0) errorReady = ((eventMask & (select.EPOLLERR | select.EPOLLHUP)) != 0) self.handleEventForFD(fd = fd, readReady = readReady, writeReady = writeReady, errorReady = errorReady)
Example #18
Source File: poll.py From vanilla with MIT License | 5 votes |
def __init__(self): self.q = select.epoll() self.to_ = { select.EPOLLIN: POLLIN, select.EPOLLOUT: POLLOUT, } self.from_ = dict((v, k) for k, v in self.to_.iteritems())
Example #19
Source File: selectors.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def register(self, fileobj, events, data=None): key = super().register(fileobj, events, data) epoll_events = 0 if events & EVENT_READ: epoll_events |= select.EPOLLIN if events & EVENT_WRITE: epoll_events |= select.EPOLLOUT self._epoll.register(key.fd, epoll_events) return key
Example #20
Source File: selectors.py From Imogen with MIT License | 5 votes |
def select(self, timeout=None): if timeout is None: timeout = -1 elif timeout <= 0: timeout = 0 else: # epoll_wait() has a resolution of 1 millisecond, round away # from zero to wait *at least* timeout seconds. timeout = math.ceil(timeout * 1e3) * 1e-3 # epoll_wait() expects `maxevents` to be greater than zero; # we want to make sure that `select()` can be called when no # FD is registered. max_ev = max(len(self._fd_to_key), 1) ready = [] try: fd_event_list = self._selector.poll(timeout, max_ev) except InterruptedError: return ready for fd, event in fd_event_list: events = 0 if event & ~select.EPOLLIN: events |= EVENT_WRITE if event & ~select.EPOLLOUT: events |= EVENT_READ key = self._key_from_fd(fd) if key: ready.append((key, events & key.events)) return ready
Example #21
Source File: pykms_Selectors.py From py-kms with The Unlicense | 5 votes |
def register(self, fileobj, events, data=None): key = super(EpollSelector, self).register(fileobj, events, data) events_mask = 0 if events & EVENT_READ: events_mask |= select.EPOLLIN if events & EVENT_WRITE: events_mask |= select.EPOLLOUT _syscall_wrapper(self._epoll.register, False, key.fd, events_mask) return key
Example #22
Source File: selectors.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def select(self, timeout=None): if timeout is not None: if timeout <= 0: timeout = 0.0 else: # select.epoll.poll() has a resolution of 1 millisecond # but luckily takes seconds so we don't need a wrapper # like PollSelector. Just for better rounding. timeout = math.ceil(timeout * 1e3) * 1e-3 timeout = float(timeout) else: timeout = -1.0 # epoll.poll() must have a float. # We always want at least 1 to ensure that select can be called # with no file descriptors registered. Otherwise will fail. max_events = max(len(self._fd_to_key), 1) ready = [] fd_events = _syscall_wrapper(self._epoll.poll, True, timeout=timeout, maxevents=max_events) for fd, event_mask in fd_events: events = 0 if event_mask & ~select.EPOLLIN: events |= EVENT_WRITE if event_mask & ~select.EPOLLOUT: events |= EVENT_READ key = self._key_from_fd(fd) if key: ready.append((key, events & key.events)) return ready
Example #23
Source File: selectors.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def register(self, fileobj, events, data=None): key = super(EpollSelector, self).register(fileobj, events, data) events_mask = 0 if events & EVENT_READ: events_mask |= select.EPOLLIN if events & EVENT_WRITE: events_mask |= select.EPOLLOUT _syscall_wrapper(self._epoll.register, False, key.fd, events_mask) return key
Example #24
Source File: selectors.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def select(self, timeout=None): if timeout is not None: if timeout <= 0: timeout = 0.0 else: # select.epoll.poll() has a resolution of 1 millisecond # but luckily takes seconds so we don't need a wrapper # like PollSelector. Just for better rounding. timeout = math.ceil(timeout * 1e3) * 1e-3 timeout = float(timeout) else: timeout = -1.0 # epoll.poll() must have a float. # We always want at least 1 to ensure that select can be called # with no file descriptors registered. Otherwise will fail. max_events = max(len(self._fd_to_key), 1) ready = [] fd_events = _syscall_wrapper(self._epoll.poll, True, timeout=timeout, maxevents=max_events) for fd, event_mask in fd_events: events = 0 if event_mask & ~select.EPOLLIN: events |= EVENT_WRITE if event_mask & ~select.EPOLLOUT: events |= EVENT_READ key = self._key_from_fd(fd) if key: ready.append((key, events & key.events)) return ready
Example #25
Source File: selectors.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def register(self, fileobj, events, data=None): key = super(EpollSelector, self).register(fileobj, events, data) events_mask = 0 if events & EVENT_READ: events_mask |= select.EPOLLIN if events & EVENT_WRITE: events_mask |= select.EPOLLOUT _syscall_wrapper(self._epoll.register, False, key.fd, events_mask) return key
Example #26
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 #27
Source File: pyro.py From pycopia with Apache License 2.0 | 5 votes |
def update(self): smap = self.smap nsmap = {} for s in self._pyrod.sockets: fd = s.fileno() if fd not in smap: self._poller.register(fd, select.EPOLLIN) nsmap[fd] = s self.smap = nsmap
Example #28
Source File: polling.py From vlcp with Apache License 2.0 | 5 votes |
def __init__(self, options = select.EPOLLET, maxwait = 60): ''' Constructor ''' self.epoll = select.epoll() self.defaultoption = options self.mask = select.EPOLLIN|select.EPOLLPRI|select.EPOLLOUT|\ select.EPOLLRDNORM|select.EPOLLRDBAND|select.EPOLLWRNORM|\ select.EPOLLWRBAND|select.EPOLLONESHOT|select.EPOLLET self.socketCounter = 0 self.maxwait = maxwait self.daemons = set() self.shouldraise = False
Example #29
Source File: epollreactor.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def removeWriter(self, writer): """ Remove a Selectable for notification of data available to write. """ if self._continuousPolling.isWriting(writer): self._continuousPolling.removeWriter(writer) return self._remove(writer, self._writes, self._reads, self._selectables, EPOLLOUT, EPOLLIN)
Example #30
Source File: ssl_wrap_util.py From snowflake-connector-python with Apache License 2.0 | 5 votes |
def register(self, fileobj, events, data=None): key = super(EpollSelector, self).register(fileobj, events, data) events_mask = 0 if events & EVENT_READ: events_mask |= select.EPOLLIN if events & EVENT_WRITE: events_mask |= select.EPOLLOUT _syscall_wrapper(self._epoll.register, False, key.fd, events_mask) return key