本文整理汇总了Python中errno.EPIPE属性的典型用法代码示例。如果您正苦于以下问题:Python errno.EPIPE属性的具体用法?Python errno.EPIPE怎么用?Python errno.EPIPE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类errno
的用法示例。
在下文中一共展示了errno.EPIPE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deliver_dnotify
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPIPE [as 别名]
def deliver_dnotify(self, dnstring, _recurse = 0):
if self.s == None:
self.connect()
if _recurse > _MAX_RECURSE:
raise Exception('Cannot reconnect: %s', self.spath)
if not dnstring.endswith('\n'):
dnstring += '\n'
while True:
try:
self.s.send(dnstring)
break
except socket.error as why:
if why[0] == EINTR:
continue
elif why[0] in (EPIPE, ENOTCONN, ECONNRESET):
self.s = None
return self.deliver_dnotify(dnstring, _recurse + 1)
raise why
# Clean any incoming data on the socket
if len(self.poller.poll(0)) > 0:
try:
self.s.recv(1024)
except:
pass
return
示例2: run_pipe
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPIPE [as 别名]
def run_pipe(channel, src_retriever, dest):
"""Emulate SageMaker pipe.
:param channel: Pipe name
:param src_retriever: Function to stream data to the pipe
:param dest: Path to directory of the pipe
"""
for epoch in range(NUM_EPOCHS):
print('Running epoch: {}'.format(epoch))
# delete previous epoch's fifo if it exists:
delete_fifo(dest, channel, epoch - 1)
try:
fifo_pth = create_fifo(dest, channel, epoch)
with open(fifo_pth, mode='bw', buffering=0) as fifo:
src_retriever(fifo)
except IOError as e:
if e.errno == errno.EPIPE:
print("Client closed current epoch's pipe before reaching EOF. "
"Continuing with next epoch...")
else:
raise
finally:
delete_fifo(dest, channel, epoch)
print('Completed pipe for channel: {}'.format(channel))
示例3: main
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPIPE [as 别名]
def main():
parser = argparse.ArgumentParser(description="Output TFRecords as JSON")
parser.add_argument("-s", "--schema", help="Path to Schema protobuf file. Uses Example if not "
"supplied.")
parser.add_argument("tf_records_paths",
metavar="TF_RECORDS_PATH",
nargs="+",
help="TFRecords file (or directory containing .tfrecords files)")
args = parser.parse_args()
try:
for json_str in tfr_read_to_json(args.tf_records_paths, args.schema):
print(json_str)
except IOError as e:
if e.errno == errno.EPIPE:
sys.exit(0)
raise e
示例4: request
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPIPE [as 别名]
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.
示例5: main
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPIPE [as 别名]
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
示例6: run
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPIPE [as 别名]
def run(self):
recv_socket = self.recv_socket
send_socket = nfc.llcp.Socket(self.llc, nfc.llcp.LOGICAL_DATA_LINK)
try:
while True:
log.info("waiting for start-of-test command")
data, addr = recv_socket.recvfrom()
if data == b'SOT':
break
echo_out_addr = recv_socket.resolve('urn:nfc:sn:dta-cl-echo-out')
while recv_socket.poll("recv"):
log.info("received data, start delay time")
time.sleep(self.options.cl_echo_delay)
while recv_socket.poll("recv", timeout=0):
data, addr = recv_socket.recvfrom()
log.info("received %d byte from sap %d", len(data), addr)
send_socket.sendto(data, echo_out_addr)
log.info("no more data, start waiting")
except nfc.llcp.Error as e:
(log.debug if e.errno == errno.EPIPE else log.error)(e)
finally:
log.info("close connection-less echo server socket")
send_socket.close()
recv_socket.close()
示例7: listen
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPIPE [as 别名]
def listen(self, socket):
try:
socket.setsockopt(nfc.llcp.SO_RCVBUF, 2)
while socket.poll("recv"):
log.info("data available, start delay time")
time.sleep(2.0)
while socket.poll("recv", timeout=0):
data, addr = socket.recvfrom()
log.info("received {0} byte from sap {1}"
.format(len(data), addr))
socket.sendto(data, addr)
log.info("no more data, start waiting")
except nfc.llcp.Error as e:
(log.debug if e.errno == errno.EPIPE else log.error)(e)
finally:
log.info("close connection-less echo server socket")
socket.close()
示例8: test_recvfrom
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPIPE [as 别名]
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
# =============================================================================
示例9: test_accept
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPIPE [as 别名]
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
示例10: page_output
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPIPE [as 别名]
def page_output(content, pager=None, file=None):
if file is None:
file = sys.stdout
if not content.endswith("\n"):
content += "\n"
pager_process = None
try:
if file != sys.stdout or not file.isatty() or not content.startswith(border("┌")):
raise AegeaException()
content_lines = content.splitlines()
content_rows = len(content_lines)
tty_cols, tty_rows = get_terminal_size()
naive_content_cols = max(len(i) for i in content_lines)
if tty_rows > content_rows and tty_cols > naive_content_cols:
raise AegeaException()
content_cols = max(len(strip_ansi_codes(i)) for i in content_lines)
if tty_rows > content_rows and tty_cols > content_cols:
raise AegeaException()
pager_process = subprocess.Popen(pager or os.environ.get("PAGER", "less -RS"), shell=True,
stdin=subprocess.PIPE, stdout=file)
pager_process.stdin.write(content.encode("utf-8"))
pager_process.stdin.close()
pager_process.wait()
if pager_process.returncode != os.EX_OK:
raise AegeaException()
except Exception as e:
if not (isinstance(e, IOError) and e.errno == errno.EPIPE):
file.write(content.encode("utf-8") if USING_PYTHON2 else content)
finally:
try:
pager_process.terminate()
except BaseException:
pass
示例11: send_raw
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPIPE [as 别名]
def send_raw(self, command, _recurse = 0, stime = None):
if _recurse > _MAX_RECURSE:
raise Exception('Cannot reconnect: %s' % (str(self.userv.address),))
if self.s == None:
self.connect()
#print('%s.send_raw(%s)' % (id(self), command))
if stime == None:
stime = MonoTime()
while True:
try:
self.s.send(command.encode())
break
except socket.error as why:
if why.errno == EINTR:
continue
elif why.errno in (EPIPE, ENOTCONN, ECONNRESET):
self.s = None
return self.send_raw(command, _recurse + 1, stime)
raise why
while True:
try:
rval = self.s.recv(1024)
if len(rval) == 0:
self.s = None
return self.send_raw(command, _MAX_RECURSE, stime)
rval = rval.decode().strip()
break
except socket.error as why:
if why.errno == EINTR:
continue
elif why.errno in (EPIPE, ENOTCONN, ECONNRESET):
self.s = None
return self.send_raw(command, _recurse + 1, stime)
raise why
rtpc_delay = stime.offsetFromNow()
return (rval, rtpc_delay)
示例12: std_exceptions
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPIPE [as 别名]
def std_exceptions(etype, value, tb):
sys.excepthook = sys.__excepthook__
if issubclass(etype, KeyboardInterrupt):
pass
elif issubclass(etype, IOError) and value.errno == errno.EPIPE:
pass
else:
sys.__excepthook__(etype, value, tb)
示例13: request
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPIPE [as 别名]
def request(self, host, handler, request_body, verbose=False):
#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 as e:
if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE):
raise
except http_client.BadStatusLine: #close after we sent request
if i:
raise
示例14: flush
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPIPE [as 别名]
def flush(self):
try:
self.wrapped.flush()
except IOError as e:
import errno
if e.errno != errno.EPIPE:
raise
示例15: out
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPIPE [as 别名]
def out(self, obj, formatter=None, out_file=None): # pylint: disable=no-self-use
""" Produces the output using the command result.
The method does not return a result as the output is written straight to the output file.
:param obj: The command result
:type obj: knack.util.CommandResultItem
:param formatter: The formatter we should use for the command result
:type formatter: function
:param out_file: The file to write output to
:type out_file: file-like object
"""
if not isinstance(obj, CommandResultItem):
raise TypeError('Expected {} got {}'.format(CommandResultItem.__name__, type(obj)))
output = formatter(obj)
try:
print(output, file=out_file, end='')
except IOError as ex:
if ex.errno == errno.EPIPE:
pass
else:
raise
except UnicodeEncodeError:
logger.warning("Unable to encode the output with %s encoding. Unsupported characters are discarded.",
out_file.encoding)
print(output.encode('ascii', 'ignore').decode('utf-8', 'ignore'),
file=out_file, end='')