Python select.EPOLLOUT Examples
The following are 30
code examples of select.EPOLLOUT().
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: 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 #3
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 #4
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 #5
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 #6
Source File: selectors.py From 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
Example #7
Source File: epollreactor.py From learn_python3_spider with MIT License | 5 votes |
def addReader(self, reader): """ Add a FileDescriptor for notification of data available to read. """ try: self._add(reader, self._reads, self._writes, self._selectables, EPOLLIN, EPOLLOUT) except IOError as e: if e.errno == errno.EPERM: # epoll(7) doesn't support certain file descriptors, # e.g. filesystem files, so for those we just poll # continuously: self._continuousPolling.addReader(reader) else: raise
Example #8
Source File: epollreactor.py From learn_python3_spider with MIT License | 5 votes |
def addWriter(self, writer): """ Add a FileDescriptor for notification of data available to write. """ try: self._add(writer, self._writes, self._reads, self._selectables, EPOLLOUT, EPOLLIN) except IOError as e: if e.errno == errno.EPERM: # epoll(7) doesn't support certain file descriptors, # e.g. filesystem files, so for those we just poll # continuously: self._continuousPolling.addWriter(writer) else: raise
Example #9
Source File: epollreactor.py From learn_python3_spider with MIT License | 5 votes |
def removeReader(self, reader): """ Remove a Selectable for notification of data available to read. """ if self._continuousPolling.isReading(reader): self._continuousPolling.removeReader(reader) return self._remove(reader, self._reads, self._writes, self._selectables, EPOLLIN, EPOLLOUT)
Example #10
Source File: selectors.py From telegram-robot-rss with Mozilla Public 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 #11
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 #12
Source File: selectors.py From cadquery-freecad-module with GNU Lesser 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 #13
Source File: selectors.py From cadquery-freecad-module with GNU Lesser 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 #14
Source File: _system_commands.py From colabtools with Apache License 2.0 | 5 votes |
def _run_command(cmd, clear_streamed_output): """Calls the shell command, forwarding input received on the stdin_socket.""" locale_encoding = locale.getpreferredencoding() if locale_encoding != _ENCODING: raise NotImplementedError( 'A UTF-8 locale is required. Got {}'.format(locale_encoding)) parent_pty, child_pty = pty.openpty() _configure_term_settings(child_pty) epoll = select.epoll() epoll.register( parent_pty, (select.EPOLLIN | select.EPOLLOUT | select.EPOLLHUP | select.EPOLLERR)) try: temporary_clearer = _tags.temporary if clear_streamed_output else _no_op with temporary_clearer(), _display_stdin_widget( delay_millis=500) as update_stdin_widget: # TODO(b/115531839): Ensure that subprocesses are terminated upon # interrupt. p = subprocess.Popen( cmd, shell=True, executable='/bin/bash', stdout=child_pty, stdin=child_pty, stderr=child_pty, close_fds=True) # The child PTY is only needed by the spawned process. os.close(child_pty) return _monitor_process(parent_pty, epoll, p, cmd, update_stdin_widget) finally: epoll.close() os.close(parent_pty)
Example #15
Source File: selectors.py From Flask-P2P with MIT License | 5 votes |
def register(self, fileobj, events, data=None): key = super(EpollSelector, self).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 #16
Source File: baseServer.py From DDDProxy with Apache License 2.0 | 5 votes |
def onIOEventFlagsChanged(self, connect): if connect._ioEventFlags != sockConnect.socketIOEventFlagsNone: eventmask = select.EPOLLERR | select.EPOLLHUP if connect._ioEventFlags & sockConnect.socketIOEventFlagsRead: eventmask |= select.EPOLLIN if connect._ioEventFlags & sockConnect.socketIOEventFlagsWrite: eventmask |= select.EPOLLOUT if not connect.registerEpoll: self.epollor.register(connect._sock.fileno(), eventmask) connect.registerEpoll = True else: self.epollor.modify(connect._sock.fileno(), eventmask) else: self.epollor.unregister(connect._sock.fileno()) connect.registerEpoll = False
Example #17
Source File: selectors.py From Flask-P2P 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 max_ev = len(self._fd_to_key) ready = [] try: fd_event_list = wrap_error(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 #18
Source File: selectors.py From telegram-robot-rss with Mozilla Public 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 #19
Source File: selectors.py From ironpython3 with Apache License 2.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 try: self._epoll.register(key.fd, epoll_events) except BaseException: super().unregister(fileobj) raise 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: 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 #22
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 #23
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 #24
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 #25
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 #26
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 #27
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 #28
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 #29
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 #30
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.