當前位置: 首頁>>代碼示例>>Python>>正文


Python select.POLLHUP屬性代碼示例

本文整理匯總了Python中select.POLLHUP屬性的典型用法代碼示例。如果您正苦於以下問題:Python select.POLLHUP屬性的具體用法?Python select.POLLHUP怎麽用?Python select.POLLHUP使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在select的用法示例。


在下文中一共展示了select.POLLHUP屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _parse_events

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLHUP [as 別名]
def _parse_events(self, events):
        """Parse ``events``.

        ``events`` is a list of events as returned by
        :meth:`select.poll.poll()`.

        Yield all parsed events.

        """
        for fd, event_mask in events:
            if self._has_event(event_mask, select.POLLNVAL):
                raise IOError('File descriptor not open: {0!r}'.format(fd))
            elif self._has_event(event_mask, select.POLLERR):
                raise IOError('Error while polling fd: {0!r}'.format(fd))

            if self._has_event(event_mask, select.POLLIN):
                yield fd, 'r'
            if self._has_event(event_mask, select.POLLOUT):
                yield fd, 'w'
            if self._has_event(event_mask, select.POLLHUP):
                yield fd, 'h' 
開發者ID:mbusb,項目名稱:multibootusb,代碼行數:23,代碼來源:poll.py

示例2: test_poll2

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLHUP [as 別名]
def test_poll2(self):
        cmd = 'for i in 0 1 2 3 4 5 6 7 8 9; do echo testing...; sleep 1; done'
        p = os.popen(cmd, 'r')
        pollster = select.poll()
        pollster.register( p, select.POLLIN )
        for tout in (0, 1000, 2000, 4000, 8000, 16000) + (-1,)*10:
            fdlist = pollster.poll(tout)
            if (fdlist == []):
                continue
            fd, flags = fdlist[0]
            if flags & select.POLLHUP:
                line = p.readline()
                if line != "":
                    self.fail('error: pipe seems to be closed, but still returns data')
                continue

            elif flags & select.POLLIN:
                line = p.readline()
                if not line:
                    break
                continue
            else:
                self.fail('Unexpected return value from select.poll: %s' % fdlist)
        p.close() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:test_poll.py

示例3: pollmask_to_str

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLHUP [as 別名]
def pollmask_to_str(mask):
        """
        Conver pool mast to string

        :param mask: poll return mask
        """
        out = ""
        if (mask & select.POLLIN):
            out += "IN "
        if (mask & select.POLLPRI):
            out += "PRI IN "
        if (mask & select.POLLOUT):
            out += "OUT "
        if (mask & select.POLLERR):
            out += "ERR "
        if (mask & select.POLLHUP):
            out += "HUP "
        if (mask & select.POLLMSG):
            out += "MSG "
        return out 
開發者ID:avocado-framework,項目名稱:avocado-vt,代碼行數:22,代碼來源:virtio_console_guest.py

示例4: worker

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLHUP [as 別名]
def worker(virt):
    """
    Worker thread (infinite) loop of virtio_guest.
    """
    global exiting
    print("PASS: Daemon start.")
    p = select.poll()
    p.register(sys.stdin.fileno())
    while not exiting:
        d = p.poll()
        if (d[0][1] == select.POLLIN):
            out = input()
            try:
                exec(out)
            except Exception:
                exc_type, exc_value, exc_traceback = sys.exc_info()
                print("On Guest exception from: \n" + "".join(
                    traceback.format_exception(exc_type,
                                               exc_value,
                                               exc_traceback)))
                print("FAIL: Guest command exception.")
        elif (d[0][1] & select.POLLHUP):
            time.sleep(0.5) 
開發者ID:avocado-framework,項目名稱:avocado-vt,代碼行數:25,代碼來源:virtio_console_guest.py

示例5: read

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLHUP [as 別名]
def read(self, size=1):
        """Read size bytes from the serial port. If a timeout is set it may
           return less characters as requested. With no timeout it will block
           until the requested number of bytes is read."""
        if self.fd is None: raise portNotOpenError
        read = bytearray()
        poll = select.poll()
        poll.register(self.fd, select.POLLIN|select.POLLERR|select.POLLHUP|select.POLLNVAL)
        if size > 0:
            while len(read) < size:
                # print "\tread(): size",size, "have", len(read)    #debug
                # wait until device becomes ready to read (or something fails)
                for fd, event in poll.poll(self._timeout*1000):
                    if event & (select.POLLERR|select.POLLHUP|select.POLLNVAL):
                        raise SerialException('device reports error (poll)')
                    #  we don't care if it is select.POLLIN or timeout, that's
                    #  handled below
                buf = os.read(self.fd, size - len(read))
                read.extend(buf)
                if ((self._timeout is not None and self._timeout >= 0) or 
                    (self._interCharTimeout is not None and self._interCharTimeout > 0)) and not buf:
                    break   # early abort on timeout
        return bytes(read) 
開發者ID:FSecureLABS,項目名稱:Jandroid,代碼行數:25,代碼來源:serialposix.py

示例6: readwrite

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLHUP [as 別名]
def readwrite(obj, flags):
    try:
        if flags & select.POLLIN:
            obj.handle_read_event()
        if flags & select.POLLOUT:
            obj.handle_write_event()
        if flags & select.POLLPRI:
            obj.handle_expt_event()
        if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
            obj.handle_close()
    except OSError as e:
        if e.args[0] not in _DISCONNECTED:
            obj.handle_error()
        else:
            obj.handle_close()
    except _reraised_exceptions:
        raise
    except:
        obj.handle_error() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:21,代碼來源:asyncore.py

示例7: poll

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLHUP [as 別名]
def poll(self, timeout = None):
            events = self._poll.poll(timeout)
            processed = []
            for fd, evt in events:
                mask = ""
                if evt & (select_module.POLLIN | select_module.POLLPRI):
                    mask += "r"
                if evt & select_module.POLLOUT:
                    mask += "w"
                if evt & select_module.POLLERR:
                    mask += "e"
                if evt & select_module.POLLHUP:
                    mask += "h"
                if evt & select_module.POLLNVAL:
                    mask += "n"
                processed.append((fd, mask))
            return processed 
開發者ID:krintoxi,項目名稱:NoobSec-Toolkit,代碼行數:19,代碼來源:compat.py

示例8: poll

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLHUP [as 別名]
def poll(self, timeout):
            if timeout is not None:
                # convert from seconds to milliseconds
                timeout *= 1000
            changes = self._poll.poll(timeout)
            results = []
            for fd, events in changes:
                f = self._get_file_object(fd)
                if events & (select.POLLIN | select.POLLPRI):
                    results.append((f, POLLER_EVENT_READ))
                elif events & (select.POLLOUT):
                    results.append((f, POLLER_EVENT_WRITE))
                elif events & (select.POLLHUP):
                    results.append((f, POLLER_EVENT_HUP))
                elif events & (select.POLLERR | select.POLLNVAL):
                    results.append((f, POLLER_EVENT_ERROR))
            return results 
開發者ID:acaceres2176,項目名稱:scylla,代碼行數:19,代碼來源:sh.py

示例9: __init__

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLHUP [as 別名]
def __init__(self, termfd, endpoint, obj):
        """
        \param termfd is a file descriptor on which to select() to
        wait for termination requests from the main CallPipe_Callee
        thread
        \param Endpoint is an endpoint of a bidirectional multiprocessing.Pipe
        \param obj is the object on which to perform the method calls
        """
        threading.Thread.__init__(self)
        self.__endpoint = endpoint
        self.__obj      = obj
        self.__waitset  = select.poll()
        eventmask = select.POLLIN | select.POLLERR \
                    | select.POLLHUP | select.POLLPRI
        self.__waitset.register(self.__endpoint.fileno(), eventmask)
        self.__waitset.register(termfd, eventmask) 
開發者ID:ActiveState,項目名稱:code,代碼行數:18,代碼來源:recipe-576509.py

示例10: _ensure_pipes

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLHUP [as 別名]
def _ensure_pipes(self):

        "Ensure that the channel is capable of communicating."

        if self.read_pipe is None or self.write_pipe is None:

            # Accept any incoming connections.

            endpoint, address = self.endpoint.accept()
            self.read_pipe = endpoint.makefile("rb", 0)
            self.write_pipe = endpoint.makefile("wb", 0)

            # Monitor the write pipe for error conditions.

            fileno = self.write_pipe.fileno()
            self.poller.register(fileno, select.POLLOUT | select.POLLHUP | select.POLLNVAL | select.POLLERR) 
開發者ID:PaulHancock,項目名稱:Aegean,代碼行數:18,代碼來源:pprocess.py

示例11: _ensure_communication

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLHUP [as 別名]
def _ensure_communication(self, timeout=None):

        "Ensure that sending and receiving are possible."

        while 1:
            self._ensure_pipes()
            fileno = self.write_pipe.fileno()
            fds = self.poller.poll(timeout)
            for fd, status in fds:
                if fd != fileno:
                    continue
                if status & (select.POLLHUP | select.POLLNVAL | select.POLLERR):

                    # Broken connection: discard it and start all over again.

                    self._reset_pipes()
                    break
            else:
                return 
開發者ID:PaulHancock,項目名稱:Aegean,代碼行數:21,代碼來源:pprocess.py

示例12: test_calls_callbacks

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLHUP [as 別名]
def test_calls_callbacks(self):
    pipe = PipeWrapper()
    event = threading.Event()

    def callback(flag):
      if flag == select.POLLIN:
        text = pipe.reader.readline()
        if text == "super beans\n":
          event.set()
      else:
        self.assertEqual(flag, select.POLLHUP)

    self.manager.add_file(pipe.reader, lambda flag: callback(flag))

    self.assertFalse(event.is_set())
    pipe.send("super beans\n")
    event.wait(1)
    self.assertTrue(event.is_set()) 
開發者ID:intelligent-agent,項目名稱:redeem,代碼行數:20,代碼來源:test_IOManager.py

示例13: __init__

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLHUP [as 別名]
def __init__(self, *args, **kwargs):
        result = super(self.__class__, self).__init__(*args, **kwargs)

        # Setting O_NONBLOCK on stdin, strout, stderr
        fcntl.fcntl(self.stdin, fcntl.F_SETFL, fcntl.fcntl(self.stdin, fcntl.F_GETFL) | os.O_NONBLOCK)
        fcntl.fcntl(self.stdout, fcntl.F_SETFL, fcntl.fcntl(self.stdout, fcntl.F_GETFL) | os.O_NONBLOCK)
        fcntl.fcntl(self.stderr, fcntl.F_SETFL, fcntl.fcntl(self.stderr, fcntl.F_GETFL) | os.O_NONBLOCK)
        
        # Using poll to get file status
        self.poller = Poll() # My own class with len()
        self.poller.register(self.stdin, select.POLLOUT | select.POLLERR | select.POLLHUP)
        self.poller.register(self.stdout, select.POLLIN | select.POLLPRI | select.POLLERR | select.POLLHUP)
        self.poller.register(self.stderr, select.POLLIN | select.POLLPRI | select.POLLERR | select.POLLHUP)

        return result

    #def __del__(self, *args, **kwargs):
        #super(self.__class__, self).__del__()
        #map(self.poller.unregister, (self.stdin, self.stdout, self.stderr)) 
開發者ID:ValdikSS,項目名稱:distvidc,代碼行數:21,代碼來源:nbsubprocess.py

示例14: readwrite

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLHUP [as 別名]
def readwrite(obj, flags):
    try:
        if flags & select.POLLIN:
            obj.handle_read_event()
        if flags & select.POLLOUT:
            obj.handle_write_event()
        if flags & select.POLLPRI:
            obj.handle_expt_event()
        if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
            obj.handle_close()
    except socket.error, e:
        if e.args[0] not in _DISCONNECTED:
            obj.handle_error()
        else:
            obj.handle_close() 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:17,代碼來源:asyncore.py

示例15: poll2

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLHUP [as 別名]
def poll2(timeout=0.0, map=None):
    # Use the poll() support added to the select module in Python 2.0
    if map is None:
        map = socket_map
    if timeout is not None:
        # timeout is in milliseconds
        timeout = int(timeout*1000)
    pollster = select.poll()
    if map:
        for fd, obj in map.items():
            flags = 0
            if obj.readable():
                flags |= select.POLLIN | select.POLLPRI
            if obj.writable():
                flags |= select.POLLOUT
            if flags:
                # Only check for exceptions if object was either readable
                # or writable.
                flags |= select.POLLERR | select.POLLHUP | select.POLLNVAL
                pollster.register(fd, flags)
        try:
            r = pollster.poll(timeout)
        except select.error, err:
            if err.args[0] != EINTR:
                raise
            r = []
        for fd, flags in r:
            obj = map.get(fd)
            if obj is None:
                continue
            readwrite(obj, flags) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:33,代碼來源:asyncore.py


注:本文中的select.POLLHUP屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。