Python errno 模块,EPIPE 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用errno.EPIPE

项目:pyOSC3    作者:Qirky    | 项目源码 | 文件源码
def _transmitMsg(self, msg):
        """Send an OSC message over a streaming socket. Raises exception if it
        should fail. If everything is transmitted properly, True is returned. If
        socket has been closed, False.
        """
        if not isinstance(msg, OSCMessage):
            raise TypeError("'msg' argument is not an OSCMessage or OSCBundle object")

        try:
            binary = msg.getBinary()
            length = len(binary)
            # prepend length of packet before the actual message (big endian)
            len_big_endian = array.array('c', '\0' * 4)
            struct.pack_into(">L", len_big_endian, 0, length)
            len_big_endian = len_big_endian.tostring()
            if self._transmit(len_big_endian) and self._transmit(binary):
                return True
            return False            
        except socket.error as e:
            if e[0] == errno.EPIPE: # broken pipe
                return False
            raise e
项目:pyOSC3    作者:Qirky    | 项目源码 | 文件源码
def _transmitMsg(self, msg):
        """Send an OSC message over a streaming socket. Raises exception if it
        should fail. If everything is transmitted properly, True is returned. If
        socket has been closed, False.
        """
        if not isinstance(msg, OSCMessage):
            raise TypeError("'msg' argument is not an OSCMessage or OSCBundle object")

        try:
            binary = msg.getBinary()
            length = len(binary)
            # prepend length of packet before the actual message (big endian)
            len_big_endian = array.array('c', '\0' * 4)
            struct.pack_into(">L", len_big_endian, 0, length)
            len_big_endian = len_big_endian.tostring()
            if self._transmit(len_big_endian) and self._transmit(binary):
                return True
            return False            
        except socket.error, e:
            if e[0] == errno.EPIPE: # broken pipe
                return False
            raise e
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def request(self, host, handler, request_body, verbose=0):
        #retry request once if cached connection has gone cold
        for i in (0, 1):
            try:
                return self.single_request(host, handler, request_body, verbose)
            except socket.error, e:
                if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE):
                    raise
            except httplib.BadStatusLine: #close after we sent request
                if i:
                    raise

    ##
    # Send a complete request, and parse the response.
    #
    # @param host Target host.
    # @param handler Target PRC handler.
    # @param request_body XML-RPC request body.
    # @param verbose Debugging flag.
    # @return Parsed response.
项目:whatstyle    作者:mikr    | 项目源码 | 文件源码
def run_with_args(args, parser):
    # type: (argparse.Namespace, argparse.ArgumentParser) -> int
    set_logging_parameters(args, parser)
    start_time = time.time()
    ret = OK
    try:
        if args.profile:
            outline("Profiling...")
            profile("ret = whatstyle(args, parser)", locals(), globals())
        else:
            ret = whatstyle(args, parser)
    except IOError as exc:
        # If the output is piped into a pager like 'less' we get a broken pipe when
        # the pager is quit early and that is ok.
        if exc.errno == errno.EPIPE:
            pass
        elif str(exc) == 'Stream closed':
            pass
        else:
            raise
        if not PY2:
            sys.stderr.close()
    iprint(INFO_TIME, 'Run time: %s seconds' % (time.time() - start_time))
    return ret
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def run(self):
        """Runs the handler, flushes the streams, and ends the request."""
        try:
            protocolStatus, appStatus = self.server.handler(self)
        except:
            traceback.print_exc(file=self.stderr)
            self.stderr.flush()
            if not self.stdout.dataWritten:
                self.server.error(self)

            protocolStatus, appStatus = FCGI_REQUEST_COMPLETE, 0

        if __debug__: _debug(1, 'protocolStatus = %d, appStatus = %d' %
                             (protocolStatus, appStatus))

        try:
            self._flush()
            self._end(appStatus, protocolStatus)
        except socket.error, e:
            if e[0] != errno.EPIPE:
                raise
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def __init__(self, fh, map=None, maxdata=None, ignore_broken_pipe=False, logger=None, **obsopt):
        """Wrap a dispatcher around the passed filehandle.

        If `ignore_broken_pipe` is `True`, an `EPIPE` or `EBADF` error will
        call `handle_close()` instead of `handle_expt()`. Useful when broken
        pipes should be handled quietly.

        `logger` is a logger which will be used to log unusual exceptions;
        otherwise, they will be printed to stderr.
        """
        self.maxdata = maxdata if maxdata else self.pipe_maxdata
        self.__logger = logger
        if ignore_broken_pipe:
            self.__ignore_errno = [EPIPE, EBADF]
        else:
            self.__ignore_errno = []
        self.__filehandle = fh
        # Check for overduplication of the file descriptor and close the extra
        fddup = os.dup(fh.fileno())
        file_dispatcher.__init__(self, fddup, map=map)
        if (self._fileno != fddup): os.close (fddup)
        Observable.__init__(self, **obsopt)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def writeSomeData(self, data):
        """Write some data to the open process.
        """
        try:
            rv = os.write(self.fd, data)
            if rv == len(data) and self.enableReadHack:
                self.startReading()
            return rv
        except IOError, io:
            if io.args[0] == errno.EAGAIN:
                return 0
            return CONNECTION_LOST
        except OSError, ose:
            if ose.errno == errno.EPIPE:
                return CONNECTION_LOST
            if ose.errno == errno.EAGAIN: # MacOS-X does this
                return 0
            raise
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def request(self, host, handler, request_body, verbose=0):
        #retry request once if cached connection has gone cold
        for i in (0, 1):
            try:
                return self.single_request(host, handler, request_body, verbose)
            except socket.error, e:
                if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE):
                    raise
            except httplib.BadStatusLine: #close after we sent request
                if i:
                    raise

    ##
    # Send a complete request, and parse the response.
    #
    # @param host Target host.
    # @param handler Target PRC handler.
    # @param request_body XML-RPC request body.
    # @param verbose Debugging flag.
    # @return Parsed response.
项目:nfcpy    作者:nfcpy    | 项目源码 | 文件源码
def test_recv(self, tco):
        pdu = nfc.llcp.pdu.UnnumberedInformation(1, 1, HEX('1122'))
        assert tco.enqueue(pdu) is True
        assert tco.recv() == pdu
        threading.Timer(0.01, tco.close).start()
        with pytest.raises(nfc.llcp.Error) as excinfo:
            tco.recv()
        assert excinfo.value.errno == errno.EPIPE
        with pytest.raises(nfc.llcp.Error) as excinfo:
            tco.recv()
        assert excinfo.value.errno == errno.ESHUTDOWN


# =============================================================================
# Logical Data Link
# =============================================================================
项目:nfcpy    作者:nfcpy    | 项目源码 | 文件源码
def test_recvfrom(self, tco):
        pdu = nfc.llcp.pdu.Symmetry()
        assert tco.enqueue(pdu) is False
        pdu = nfc.llcp.pdu.UnnumberedInformation(1, 1, (tco.recv_miu+1) * b'1')
        assert tco.enqueue(pdu) is False
        pdu = nfc.llcp.pdu.UnnumberedInformation(1, 1, HEX('1122'))
        assert tco.enqueue(pdu) is True
        assert tco.recvfrom() == (pdu.data, pdu.ssap)
        threading.Timer(0.01, tco.close).start()
        with pytest.raises(nfc.llcp.Error) as excinfo:
            tco.recvfrom()
        assert excinfo.value.errno == errno.EPIPE
        with pytest.raises(nfc.llcp.Error) as excinfo:
            tco.recvfrom()
        assert excinfo.value.errno == errno.ESHUTDOWN


# =============================================================================
# Data Link Connection
# =============================================================================
项目:nfcpy    作者:nfcpy    | 项目源码 | 文件源码
def test_accept(self, tco):
        with pytest.raises(nfc.llcp.Error) as excinfo:
            tco.accept()
        assert excinfo.value.errno == errno.EINVAL
        tco.setsockopt(nfc.llcp.SO_RCVMIU, 1000)
        tco.setsockopt(nfc.llcp.SO_RCVBUF, 2)
        tco.listen(backlog=1)
        assert tco.state.LISTEN is True
        tco.enqueue(nfc.llcp.pdu.Connect(tco.addr, 17, 500, 15))
        dlc = tco.accept()
        assert isinstance(dlc, nfc.llcp.tco.DataLinkConnection)
        assert dlc.state.ESTABLISHED is True
        assert dlc.getsockopt(nfc.llcp.SO_RCVMIU) == 1000
        assert dlc.getsockopt(nfc.llcp.SO_SNDMIU) == 500
        assert dlc.getsockopt(nfc.llcp.SO_RCVBUF) == 2
        assert tco.dequeue(128, 4) == \
            nfc.llcp.pdu.ConnectionComplete(17, tco.addr, 1000, 2)
        threading.Timer(0.01, tco.close).start()
        with pytest.raises(nfc.llcp.Error) as excinfo:
            tco.accept()
        assert excinfo.value.errno == errno.EPIPE
        with pytest.raises(nfc.llcp.Error) as excinfo:
            tco.accept()
        assert excinfo.value.errno == errno.ESHUTDOWN
项目:nfcpy    作者:nfcpy    | 项目源码 | 文件源码
def send(self, message, flags):
        with self.send_token:
            if not self.state.ESTABLISHED:
                self.err("send() in socket state {0}".format(self.state))
                if self.state.CLOSE_WAIT:
                    raise err.Error(errno.EPIPE)
                raise err.Error(errno.ENOTCONN)
            if len(message) > self.send_miu:
                raise err.Error(errno.EMSGSIZE)
            while self.send_window_slots == 0 and self.state.ESTABLISHED:
                if flags & nfc.llcp.MSG_DONTWAIT:
                    raise err.Error(errno.EWOULDBLOCK)
                self.log("waiting on busy send window")
                self.send_token.wait()
            self.log("send {0} byte on {1}".format(len(message), str(self)))
            if self.state.ESTABLISHED:
                send_pdu = pdu.Information(self.peer, self.addr, data=message)
                send_pdu.ns = self.send_cnt
                self.send_cnt = (self.send_cnt + 1) % 16
                super(DataLinkConnection, self).send(send_pdu, flags)
            return self.state.ESTABLISHED is True
项目:goreviewpartner    作者:pnprog    | 项目源码 | 文件源码
def _run_gtp_session(engine, read, write):
    while True:
        try:
            line = read()
        except EOFError:
            break
        response, end_session = engine.handle_line(line)
        if response is not None:
            try:
                write(response)
            except IOError, e:
                if e.errno == errno.EPIPE:
                    raise ControllerDisconnected(*e.args)
                else:
                    raise
        if end_session:
            break
项目:cuny-bdif    作者:aristotle-tek    | 项目源码 | 文件源码
def test_broken_pipe_recovery(self):
        """
        Tests handling of a Broken Pipe (which interacts with an httplib bug)
        """
        exception = IOError(errno.EPIPE, "Broken pipe")
        harness = CallbackTestHarness(exception=exception)
        res_upload_handler = ResumableUploadHandler(num_retries=1)
        small_src_file_as_string, small_src_file = self.make_small_file()
        small_src_file.seek(0)
        dst_key = self._MakeKey(set_contents=False)
        dst_key.set_contents_from_file(
            small_src_file, cb=harness.call,
            res_upload_handler=res_upload_handler)
        # Ensure uploaded object has correct content.
        self.assertEqual(SMALL_KEY_SIZE, dst_key.size)
        self.assertEqual(small_src_file_as_string,
                         dst_key.get_contents_as_string())
项目:cuny-bdif    作者:aristotle-tek    | 项目源码 | 文件源码
def test_broken_pipe_recovery(self):
        """
        Tests handling of a Broken Pipe (which interacts with an httplib bug)
        """
        exception = IOError(errno.EPIPE, "Broken pipe")
        harness = CallbackTestHarness(exception=exception)
        res_download_handler = ResumableDownloadHandler(num_retries=1)
        dst_fp = self.make_dst_fp()
        small_src_key_as_string, small_src_key = self.make_small_key()
        small_src_key.get_contents_to_file(
            dst_fp, cb=harness.call,
            res_download_handler=res_download_handler)
        # Ensure downloaded object has correct content.
        self.assertEqual(SMALL_KEY_SIZE,
                         get_cur_file_size(dst_fp))
        self.assertEqual(small_src_key_as_string,
                         small_src_key.get_contents_as_string())
项目:PeekabooAV    作者:scVENUS    | 项目源码 | 文件源码
def __send_message(self, msg):
        """
        Write a message to the socket.

        :param msg: The message to send (max. 1024 bytes).
        """
        if self.__socket is None:
            return
        try:
            self.__socket.send(msg)
            logger.debug('Message send: %s ' % msg)
        except IOError as e:
            if e.errno == errno.EPIPE:
                logger.warning('Unable send message "%s". Broken pipe.' % msg)
            else:
                logger.exception(e)
项目:qmpbackup    作者:abbbi    | 项目源码 | 文件源码
def cmd_obj(self, qmp_cmd):
        """
        Send a QMP command to the QMP Monitor.

        @param qmp_cmd: QMP command to be sent as a Python dict
        @return QMP response as a Python dict or None if the connection has
                been closed
        """
        if self._debug:
            print >>sys.stderr, "QMP:>>> %s" % qmp_cmd
        try:
            self.__sock.sendall(json.dumps(qmp_cmd))
        except socket.error as err:
            if err[0] == errno.EPIPE:
                return
            raise socket.error(err)
        resp = self.__json_read()
        if self._debug:
            print >>sys.stderr, "QMP:<<< %s" % resp
        return resp
项目:ezpy    作者:jhermann    | 项目源码 | 文件源码
def run():
    """Execute main loop."""
    try:
        setup()
        try:
            parser, args = make_argparser()
            mainloop(parser, args)
        except KeyboardInterrupt as exc:
            sys.stderr.flush()
            sys.exit(2)
        except IOError as exc:
            if exc.errno == errno.EPIPE:  # downstream is done with our output
                sys.stderr.flush()
                sys.exit(0)
            else:
                raise
    finally:
        logging.shutdown()
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def main(logfile):
    p = hotshot.Profile(logfile)
    benchtime, stones = p.runcall(test.pystone.pystones)
    p.close()

    print "Pystone(%s) time for %d passes = %g" % \
          (test.pystone.__version__, test.pystone.LOOPS, benchtime)
    print "This machine benchmarks at %g pystones/second" % stones

    stats = hotshot.stats.load(logfile)
    stats.strip_dirs()
    stats.sort_stats('time', 'calls')
    try:
        stats.print_stats(20)
    except IOError, e:
        if e.errno != errno.EPIPE:
            raise
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def request(self, host, handler, request_body, verbose=0):
        #retry request once if cached connection has gone cold
        for i in (0, 1):
            try:
                return self.single_request(host, handler, request_body, verbose)
            except socket.error, e:
                if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE):
                    raise
            except httplib.BadStatusLine: #close after we sent request
                if i:
                    raise

    ##
    # Send a complete request, and parse the response.
    #
    # @param host Target host.
    # @param handler Target PRC handler.
    # @param request_body XML-RPC request body.
    # @param verbose Debugging flag.
    # @return Parsed response.
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def main():
    p = os.popen('du ' + ' '.join(sys.argv[1:]), 'r')
    total, d = None, {}
    for line in p.readlines():
        i = 0
        while line[i] in '0123456789': i = i+1
        size = eval(line[:i])
        while line[i] in ' \t': i = i+1
        filename = line[i:-1]
        comps = filename.split('/')
        if comps[0] == '': comps[0] = '/'
        if comps[len(comps)-1] == '': del comps[len(comps)-1]
        total, d = store(size, comps, total, d)
    try:
        display(total, d)
    except IOError, e:
        if e.errno != errno.EPIPE:
            raise
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def main(logfile):
    p = hotshot.Profile(logfile)
    benchtime, stones = p.runcall(test.pystone.pystones)
    p.close()

    print "Pystone(%s) time for %d passes = %g" % \
          (test.pystone.__version__, test.pystone.LOOPS, benchtime)
    print "This machine benchmarks at %g pystones/second" % stones

    stats = hotshot.stats.load(logfile)
    stats.strip_dirs()
    stats.sort_stats('time', 'calls')
    try:
        stats.print_stats(20)
    except IOError, e:
        if e.errno != errno.EPIPE:
            raise
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def request(self, host, handler, request_body, verbose=0):
        #retry request once if cached connection has gone cold
        for i in (0, 1):
            try:
                return self.single_request(host, handler, request_body, verbose)
            except socket.error, e:
                if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE):
                    raise
            except httplib.BadStatusLine: #close after we sent request
                if i:
                    raise

    ##
    # Send a complete request, and parse the response.
    #
    # @param host Target host.
    # @param handler Target PRC handler.
    # @param request_body XML-RPC request body.
    # @param verbose Debugging flag.
    # @return Parsed response.
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def main():
    p = os.popen('du ' + ' '.join(sys.argv[1:]), 'r')
    total, d = None, {}
    for line in p.readlines():
        i = 0
        while line[i] in '0123456789': i = i+1
        size = eval(line[:i])
        while line[i] in ' \t': i = i+1
        filename = line[i:-1]
        comps = filename.split('/')
        if comps[0] == '': comps[0] = '/'
        if comps[len(comps)-1] == '': del comps[len(comps)-1]
        total, d = store(size, comps, total, d)
    try:
        display(total, d)
    except IOError, e:
        if e.errno != errno.EPIPE:
            raise
项目:gluster-nagios-common    作者:gluster    | 项目源码 | 文件源码
def write(self, data):
            if hasattr(data, "tobytes"):
                data = data.tobytes()
            with self._parent._streamLock:
                oldPos = self._stream.pos
                self._stream.pos = self._stream.len
                self._stream.write(data)
                self._stream.pos = oldPos

            while self._stream.len > 0 and not self._streamClosed:
                self._parent._processStreams()

            if self._streamClosed:
                self._closed = True

            if self._stream.len != 0:
                raise IOError(errno.EPIPE,
                              "Could not write all data to stream")

            return len(data)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def writeSomeData(self, data):
        """Write some data to the open process.
        """
        try:
            rv = os.write(self.fd, data)
            if rv == len(data) and self.enableReadHack:
                self.startReading()
            return rv
        except IOError, io:
            if io.args[0] == errno.EAGAIN:
                return 0
            return CONNECTION_LOST
        except OSError, ose:
            if ose.errno == errno.EPIPE:
                return CONNECTION_LOST
            if ose.errno == errno.EAGAIN: # MacOS-X does this
                return 0
            raise
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def request(self, host, handler, request_body, verbose=0):
        #retry request once if cached connection has gone cold
        for i in (0, 1):
            try:
                return self.single_request(host, handler, request_body, verbose)
            except socket.error, e:
                if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE):
                    raise
            except httplib.BadStatusLine: #close after we sent request
                if i:
                    raise

    ##
    # Send a complete request, and parse the response.
    #
    # @param host Target host.
    # @param handler Target PRC handler.
    # @param request_body XML-RPC request body.
    # @param verbose Debugging flag.
    # @return Parsed response.
项目:bitpay-brick    作者:javgh    | 项目源码 | 文件源码
def accept(self):
        with self.lock:
            if self.state.SHUTDOWN:
                raise Error(errno.EBADF)
            if not self.state.LISTEN:
                self.err("accept() but socket state is {0}".format(self.state))
                raise Error(errno.EINVAL)
            self.recv_buf += 1
            try: pdu = super(DataLinkConnection, self).recv()
            except IndexError: raise Error(errno.EPIPE)
            self.recv_buf -= 1
            if isinstance(pdu, Connect):
                dlc = DataLinkConnection(self.recv_miu, self.recv_win)
                dlc.addr = self.addr
                dlc.peer = pdu.ssap
                dlc.send_miu = pdu.miu
                dlc.send_win = pdu.rw
                pdu = ConnectionComplete(dlc.peer, dlc.addr)
                pdu.miu, pdu.rw = dlc.recv_miu, dlc.recv_win
                log.info("accepting CONNECT from SAP %d" % dlc.peer)
                dlc.state.ESTABLISHED = True
                self.send_queue.append(pdu)
                return dlc
            raise RuntimeError("only CONNECT expected, not "+ pdu.name)
项目:bitpay-brick    作者:javgh    | 项目源码 | 文件源码
def send(self, message):
        with self.send_token:
            if not self.state.ESTABLISHED:
                self.err("send() in socket state {0}".format(self.state))
                if self.state.CLOSE_WAIT:
                    raise Error(errno.EPIPE)
                raise Error(errno.ENOTCONN)
            if len(message) > self.send_miu:
                raise Error(errno.EMSGSIZE)
            while self.send_window_slots == 0 and self.state.ESTABLISHED:
                self.log("waiting on busy send window")
                self.send_token.wait()
            self.log("send() {0}".format(str(self)))
            if self.state.ESTABLISHED:
                pdu = Information(self.peer, self.addr, sdu=message)
                pdu.ns = self.send_cnt
                self.send_cnt = (self.send_cnt + 1) % 16
                super(DataLinkConnection, self).send(pdu)
            return self.state.ESTABLISHED == True
项目:xivo-ctid-ng    作者:wazo-pbx    | 项目源码 | 文件源码
def _connect(self):
        logger.debug('ARI client listening...')
        try:
            with self._running():
                self.client.run(apps=[APPLICATION_NAME])
        except socket.error as e:
            if e.errno == errno.EPIPE:
                # bug in ari-py when calling client.close(): ignore it and stop
                logger.error('Error while listening for ARI events: %s', e)
                return
            else:
                self._connection_error(e)
        except (WebSocketException, HTTPError) as e:
            self._connection_error(e)
        except ValueError:
            logger.warning('Received non-JSON message from ARI... disconnecting')
            self.client.close()
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def read(fd, n):
    """read(fd, buffersize) -> string

    Read a file descriptor."""
    while True:
        try:
            return __original_read__(fd, n)
        except (OSError, IOError) as e:
            if get_errno(e) != errno.EAGAIN:
                raise
        except socket.error as e:
            if get_errno(e) == errno.EPIPE:
                return ''
            raise
        try:
            hubs.trampoline(fd, read=True)
        except hubs.IOClosed:
            return ''
项目:flux_line_bot    作者:blesscat    | 项目源码 | 文件源码
def get_resp(self, timeout=180.0):
        rl = select((self.sock, ), (), (), timeout)[0]
        if not rl:
            raise RobotError("get resp timeout")
        bml = msg_waitall(self.sock, 2, timeout)
        if not bml:
            logger.error("Message payload recv error")
            raise socket.error(EPIPE, "Broken pipe")

        message_length = struct.unpack("<H", bml)[0]

        message = b""

        while len(message) != message_length:
            buf = self.sock.recv(message_length - len(message))

            if not buf:
                logger.error("Recv empty message")
                raise socket.error(EPIPE, "Broken pipe")
            message += buf

        return message
项目:tracknodes    作者:NREL    | 项目源码 | 文件源码
def print_history(self):
        """
        Print database information to STDOUT
        """
        try:
            print("History of Nodes")
            print("=========")
            self.cur.execute("SELECT * FROM NodeStates ORDER BY datetime(Time) DESC")
            rows = self.cur.fetchall()
            for row in rows:
                print("%s | %s | %s | '%s'" % (row[0], row[3], TrackNodes.decode_state(row[1]), row[2]))
            print("")
        except IOError as e:
            if e.errno == errno.EPIPE:
                # Perhaps output was piped to less and was quit prior to EOF
                return
项目:treadmill    作者:Morgan-Stanley    | 项目源码 | 文件源码
def _publish_status(self, status_socket, status_info):
        """Publish service status on the incomming connection on socket
        """
        with contextlib.closing(status_socket.accept()[0]) as clt:
            clt_stream = clt.makefile(mode='w')
            try:
                yaml.dump(status_info,
                          explicit_start=True, explicit_end=True,
                          default_flow_style=False,
                          stream=clt_stream)
                clt_stream.flush()
            except socket.error as err:
                if err.errno == errno.EPIPE:
                    pass
                else:
                    raise
项目:CodeLabs    作者:TheIoTLearningInitiative    | 项目源码 | 文件源码
def do_GET(self):

        query = self.path.split("?",1)[-1]
        filepath = urllib.unquote_plus(query)

        self.suppress_socket_error_report = None

        self.send_headers(filepath)       

        print "sending data"      
        try: 
            self.write_response(filepath)
        except socket.error, e:     
            if isinstance(e.args, tuple):
                if e[0] in (errno.EPIPE, errno.ECONNRESET):
                   print "disconnected"
                   self.suppress_socket_error_report = True
                   return

            raise
项目:pycos    作者:pgiri    | 项目源码 | 文件源码
def _async_recv_msg(self):
        """Internal use only; use 'recv_msg' with 'yield' instead.

        Message is tagged with length of the payload (data). This method
        receives length of payload, then the payload and returns the payload.
        """
        n = AsyncSocket._MsgLengthSize
        try:
            data = yield self.recvall(n)
        except socket.error as err:
            if err.args[0] == 'hangup':
                # raise socket.error(errno.EPIPE, 'Insufficient data')
                raise StopIteration('')
            else:
                raise
        if len(data) != n:
            # raise socket.error(errno.EPIPE, 'Insufficient data: %s / %s' % (len(data), n))
            raise StopIteration('')
        n = struct.unpack('>L', data)[0]
        # assert n >= 0
        if n:
            try:
                data = yield self.recvall(n)
            except socket.error as err:
                if err.args[0] == 'hangup':
                    # raise socket.error(errno.EPIPE, 'Insufficient data')
                    raise StopIteration('')
                else:
                    raise
            if len(data) != n:
                # raise socket.error(errno.EPIPE, 'Insufficient data: %s / %s' % (len(data), n))
                raise StopIteration('')
            raise StopIteration(data)
        else:
            raise StopIteration('')
项目:pycos    作者:pgiri    | 项目源码 | 文件源码
def _sync_recv_msg(self):
        """Internal use only; use 'recv_msg' instead.

        Synchronous version of async_recv_msg.
        """
        n = AsyncSocket._MsgLengthSize
        try:
            data = self._sync_recvall(n)
        except socket.error as err:
            if err.args[0] == 'hangup':
                # raise socket.error(errno.EPIPE, 'Insufficient data')
                return ''
            else:
                raise
        if len(data) != n:
            # raise socket.error(errno.EPIPE, 'Insufficient data: %s / %s' % (len(data), n))
            return ''
        n = struct.unpack('>L', data)[0]
        # assert n >= 0
        if n:
            try:
                data = self._sync_recvall(n)
            except socket.error as err:
                if err.args[0] == 'hangup':
                    # raise socket.error(errno.EPIPE, 'Insufficient data')
                    return ''
                else:
                    raise
            if len(data) != n:
                # raise socket.error(errno.EPIPE, 'Insufficient data: %s / %s' % (len(data), n))
                return ''
            return data
        else:
            return ''
项目:pycos    作者:pgiri    | 项目源码 | 文件源码
def _async_recv_msg(self):
        """Internal use only; use 'recv_msg' with 'yield' instead.

        Message is tagged with length of the payload (data). This method
        receives length of payload, then the payload and returns the payload.
        """
        n = AsyncSocket._MsgLengthSize
        try:
            data = yield self.recvall(n)
        except socket.error as err:
            if err.args[0] == 'hangup':
                # raise socket.error(errno.EPIPE, 'Insufficient data')
                raise StopIteration(b'')
            else:
                raise
        if len(data) != n:
            # raise socket.error(errno.EPIPE, 'Insufficient data: %s / %s' % (len(data), n))
            raise StopIteration(b'')
        n = struct.unpack('>L', data)[0]
        # assert n >= 0
        if n:
            try:
                data = yield self.recvall(n)
            except socket.error as err:
                if err.args[0] == 'hangup':
                    # raise socket.error(errno.EPIPE, 'Insufficient data')
                    raise StopIteration(b'')
                else:
                    raise
            if len(data) != n:
                # raise socket.error(errno.EPIPE, 'Insufficient data: %s / %s' % (len(data), n))
                raise StopIteration(b'')
            raise StopIteration(data)
        else:
            raise StopIteration(b'')
项目:pycos    作者:pgiri    | 项目源码 | 文件源码
def _sync_recv_msg(self):
        """Internal use only; use 'recv_msg' instead.

        Synchronous version of async_recv_msg.
        """
        n = AsyncSocket._MsgLengthSize
        try:
            data = self._sync_recvall(n)
        except socket.error as err:
            if err.args[0] == 'hangup':
                # raise socket.error(errno.EPIPE, 'Insufficient data')
                return b''
            else:
                raise
        if len(data) != n:
            # raise socket.error(errno.EPIPE, 'Insufficient data: %s / %s' % (len(data), n))
            return b''
        n = struct.unpack('>L', data)[0]
        # assert n >= 0
        if n:
            try:
                data = self._sync_recvall(n)
            except socket.error as err:
                if err.args[0] == 'hangup':
                    # raise socket.error(errno.EPIPE, 'Insufficient data')
                    return b''
                else:
                    raise
            if len(data) != n:
                # raise socket.error(errno.EPIPE, 'Insufficient data: %s / %s' % (len(data), n))
                return b''
            return data
        else:
            return b''
项目:personal-identification-pipeline    作者:TeamErlich    | 项目源码 | 文件源码
def get_dup_read_ids(filename):
    """
    Reads a SAM file, returns a set() of duplicated reads
    (reads which are listed more than once)
    """
    try:
        seen_ids = set()
        dup_ids = set()

        sam=file(filename,'r')

        for linenum,line in enumerate(sam):
            err = "input error in '%s' line %d: " % (filename, linenum+1)
            line = line.strip()

            if line[:1]=='@':
                continue

            flds = line.split('\t')
            read_id = flds[0]

            if read_id in seen_ids:
                dup_ids.add(read_id)

            seen_ids.add(read_id)

        return dup_ids

    except IOError as e:
        if e.errno == errno.EPIPE:
            sys.exit(0) # exit silently

        # TODO: this is a cop-out, hard to tell what's the exact error
        #       and give informative,useful error message to the user.
        sys.exit("I/O error: %s" % (str(e)))
项目:personal-identification-pipeline    作者:TeamErlich    | 项目源码 | 文件源码
def filter_sam_dups(filename,ids_to_discard):
    """
    Reads a SAM file, returns a set() of duplicated reads
    (reads which are listed more than once)
    """
    try:
        sam=file(filename,'r')

        for linenum,line in enumerate(sam):
            err = "input error in '%s' line %d: " % (filename, linenum+1)
            line = line.strip()

            if line[:1]=='@':
                print line
                continue

            flds = line.split('\t')
            read_id = flds[0]

            if not (read_id in ids_to_discard):
                print line

    except IOError as e:
        if e.errno == errno.EPIPE:
            sys.exit(0) # exit silently

        # TODO: this is a cop-out, hard to tell what's the exact error
        #       and give informative,useful error message to the user.
        sys.exit("I/O error: %s" % (str(e)))
项目:personal-identification-pipeline    作者:TeamErlich    | 项目源码 | 文件源码
def process_times(filename):
    """
    Remove the path (dirname) from the second field of the 'times' file.
    """
    try:
        f=open(filename,'r')
        for linenum,line in enumerate(f):
            err = "input error in '%s' line %d: " % (filename, linenum+1)

            line = line.strip()
            flds = line.split('\t')
            if len(flds) != 11:
                sys.exit(err + "expecting 11 fields, found %d - is this a " \
                         "'poretools times' file?" % (len(flds)))

            # First line: validate, then print as-is
            if linenum==0:
                if flds[0] != "channel":
                    sys.exit(err + "expecting header line (first word: " \
                             "'channel') - is this a 'poretools times' file?")
                print '\t'.join(flds)
                continue


            # other lines - remove path from second field.
            flds[1] = basename(flds[1])
            print '\t'.join(flds)


    except IOError as e:
        if e.errno == errno.EPIPE:
            sys.exit(0) # exit silently

        # TODO: this is a cop-out, hard to tell what's the exact error
        #       and give informative,useful error message to the user.
        sys.exit("I/O error: %s" % (str(e)))
项目:IgDiscover    作者:NBISweden    | 项目源码 | 文件源码
def main(args):
    """
    Parse IgBLAST output
    """
    n = 0
    if args.vdatabase:
        with SequenceReader(args.vdatabase) as fr:
            v_database = {record.name: record.sequence.upper() for record in fr}
    else:
        v_database = None

    detected_cdr3s = 0
    writer = TableWriter(sys.stdout)
    with SequenceReader(args.fasta) as sequences, xopen(args.igblast) as igblast:
        parser = ExtendedIgBlastParser(sequences, igblast, v_database)
        for record in parser:
            n += 1
            d = record.asdict()
            if d['CDR3_aa']:
                detected_cdr3s += 1
            if args.rename is not None:
                d['name'] = "{}seq{}".format(args.rename, n)
            try:
                writer.write(d)
            except IOError as e:
                if e.errno == errno.EPIPE:
                    sys.exit(1)
                raise
    logger.info('%d IgBLAST assignments parsed and written', n)
    logger.info('CDR3s detected in %.1f%% of all sequences', detected_cdr3s / n * 100)

    if args.stats:
        stats = {'total': n, 'detected_cdr3s': detected_cdr3s}
        with open(args.stats, 'w') as f:
            json.dump(stats, f)
            print(file=f)
项目:data_pipeline    作者:Yelp    | 项目源码 | 文件源码
def run(self):
        try:
            self._compress_streaming_json()
        except IOError as e:
            if e.errno == errno.EPIPE:
                # just stop if the pipe breaks
                pass
            else:
                raise
        finally:
            self._close_file()
项目:data_pipeline    作者:Yelp    | 项目源码 | 文件源码
def run(self):
        try:
            self._parse_binlog()
        except IOError as e:
            if e.errno == errno.EPIPE:
                # just stop if the pipe breaks
                pass
            else:
                raise
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def communicate(self, input=None):
        """Interact with process: Send data to stdin.  Read data from
        stdout and stderr, until end-of-file is reached.  Wait for
        process to terminate.  The optional input argument should be a
        string to be sent to the child process, or None, if no data
        should be sent to the child.

        communicate() returns a tuple (stdout, stderr)."""

        # Optimization: If we are only using one pipe, or no pipe at
        # all, using select() or threads is unnecessary.
        if [self.stdin, self.stdout, self.stderr].count(None) >= 2:
            stdout = None
            stderr = None
            if self.stdin:
                if input:
                    try:
                        self.stdin.write(input)
                    except IOError as e:
                        if e.errno != errno.EPIPE and e.errno != errno.EINVAL:
                            raise
                self.stdin.close()
            elif self.stdout:
                stdout = self.stdout.read()
                self.stdout.close()
            elif self.stderr:
                stderr = self.stderr.read()
                self.stderr.close()
            self.wait()
            return (stdout, stderr)

        return self._communicate(input)
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def send(self, input):
            if not self.stdin:
                return None

            if not select.select([], [self.stdin], [], 0)[1]:
                return 0

            try:
                written = os.write(self.stdin.fileno(), input)
            except OSError:
                if geterror()[0] == errno.EPIPE: #broken pipe
                    return self._close('stdin')
                raise

            return written
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def _notifyParent(self, parent, msg):
        """Send message to parent, ignoring EPIPE and retrying on EAGAIN"""
        while True:
            try:
                parent.send(msg)
                return True
            except socket.error, e:
                if e[0] == errno.EPIPE:
                    return False # Parent is gone
                if e[0] == errno.EAGAIN:
                    # Wait for socket change before sending again
                    select.select([], [parent], [])
                else:
                    raise
项目:shadowsocksR-b    作者:hao35954514    | 项目源码 | 文件源码
def run(self):
        events = []
        while not self._stopping:
            asap = False
            try:
                events = self.poll(TIMEOUT_PRECISION)
            except (OSError, IOError) as e:
                if errno_from_exception(e) in (errno.EPIPE, errno.EINTR):
                    # EPIPE: Happens when the client closes the connection
                    # EINTR: Happens when received a signal
                    # handles them as soon as possible
                    asap = True
                    logging.debug('poll:%s', e)
                else:
                    logging.error('poll:%s', e)
                    import traceback
                    traceback.print_exc()
                    continue

            handle = False
            for sock, fd, event in events:
                handler = self._fdmap.get(fd, None)
                if handler is not None:
                    handler = handler[1]
                    try:
                        handle = handler.handle_event(sock, fd, event) or handle
                    except (OSError, IOError) as e:
                        shell.print_exception(e)
            now = time.time()
            if asap or now - self._last_time >= TIMEOUT_PRECISION:
                for callback in self._periodic_callbacks:
                    callback()
                self._last_time = now
            if events and not handle:
                time.sleep(0.001)
项目:shadowsocksR-b    作者:hao35954514    | 项目源码 | 文件源码
def _on_local_error(self):
        if self._local_sock:
            err = eventloop.get_sock_error(self._local_sock)
            if err.errno not in [errno.ECONNRESET, errno.EPIPE]:
                logging.error(err)
                logging.error("local error, exception from %s:%d" % (self._client_address[0], self._client_address[1]))
        self.destroy()