本文整理汇总了Python中signal.SIGPIPE属性的典型用法代码示例。如果您正苦于以下问题:Python signal.SIGPIPE属性的具体用法?Python signal.SIGPIPE怎么用?Python signal.SIGPIPE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类signal
的用法示例。
在下文中一共展示了signal.SIGPIPE属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: learn_func
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGPIPE [as 别名]
def learn_func(**kwargs):
if not kwargs['quiet']:
print("Reading " + kwargs['archive'], file=sys.stderr)
archive = tbu.archive.read_csv(kwargs.get('archive'))
gen = checking.generator(archive, **kwargs)
tweets = (tweet.replace(u'\n', u' ') + '\n' for tweet in gen)
if kwargs['output'] in ('-', '/dev/stdout'):
signal(SIGPIPE, SIG_DFL)
sys.stdout.writelines(tweets)
else:
if not kwargs['quiet']:
print("Writing " + kwargs['output'], file=sys.stderr)
with open(kwargs.get('output'), 'w') as f:
f.writelines(tweets)
示例2: __doChildStart
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGPIPE [as 别名]
def __doChildStart(self):
"guts of start child process"
self.statusPipe.postForkChild()
_setPgid(os.getpid(), self.dag.pgid if (self.dag.pgid is not None) else os.getpid())
cmd = self.__buildCmd()
self.__stdioSetup(self.stdin, 0)
self.__stdioSetup(self.stdout, 1)
self.__stdioSetup(self.stderr, 2)
self.__closeFiles()
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
os.execvp(cmd[0], cmd)
示例3: _handleExit
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGPIPE [as 别名]
def _handleExit(self, waitStat):
"""Handle process exiting, saving status Call close on all PInOut objects
to disassociate """
self.finished = True
assert(os.WIFEXITED(waitStat) or os.WIFSIGNALED(waitStat))
self.returncode = os.WEXITSTATUS(waitStat) if os.WIFEXITED(waitStat) else -os.WTERMSIG(waitStat)
if not ((self.returncode == 0) or (self.returncode == -signal.SIGPIPE)):
self.__handleErrExit()
for pin in self.pins:
pin.close()
for pout in self.pouts:
pout.close()
示例4: signal_to_string
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGPIPE [as 别名]
def signal_to_string(self, signalNumber):
if signalNumber < 0:
signalNumber = signalNumber * -1
if signalNumber == signal.SIGINT:
return "SIGINT - Interrupt (Ctrl+C)"
elif signalNumber == signal.SIGKILL:
return "SIGKILL - Killed"
elif signalNumber == signal.SIGTERM:
return "SIGTERM - Terminated"
elif signalNumber == signal.SIGSEGV:
return "SIGSEGV - Segmentation fault"
elif signalNumber == signal.SIGHUP:
return "SIGHUP - Hang up"
elif signalNumber == signal.SIGBUS:
return "SIGBUS - Bus error"
elif signalNumber == signal.SIGILL:
return "SIGILL - Illegal instruction"
elif signalNumber == signal.SIGFPE:
return "SIGFPE - Floating point exception"
elif signalNumber == signal.SIGPIPE:
return "SIGPIPE - Broken pipe (write to pipe with no readers)"
elif signalNumber == signal.SIGABRT:
return "SIGABRT - Called abort()"
elif signalNumber == signal.SIGXFSZ:
return "SIGXFSZ - Process created files that were too big."
elif signalNumber == signal.SIGXCPU:
return "SIGXCPU - Process used too much CPU time."
else:
return "Unknown signal #" + str(signalNumber)
示例5: get_exc_exit_code_would_raise
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGPIPE [as 别名]
def get_exc_exit_code_would_raise(exit_code, ok_codes, sigpipe_ok):
exc = None
success = exit_code in ok_codes
bad_sig = -exit_code in SIGNALS_THAT_SHOULD_THROW_EXCEPTION
# if this is a piped command, SIGPIPE must be ignored by us and not raise an
# exception, since it's perfectly normal for the consumer of a process's
# pipe to terminate early
if sigpipe_ok and -exit_code == signal.SIGPIPE:
bad_sig = False
success = True
if not success or bad_sig:
exc = get_rc_exc(exit_code)
return exc
示例6: _reset_signals
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGPIPE [as 别名]
def _reset_signals(signals=None):
"""A context that save the current signal handlers restore them when leaving.
By default, it does so for SIGINT, SIGTERM, SIGHUP and SIGPIPE.
"""
if signals is None:
signals = (signal.SIGINT, signal.SIGTERM, signal.SIGHUP, signal.SIGPIPE)
saved = {sig: ctypes.pythonapi.PyOS_getsig(sig) for sig in signals}
try:
yield
finally:
for sig, handler in saved.items():
if ctypes.pythonapi.PyOS_getsig(sig) != handler:
ctypes.pythonapi.PyOS_setsig(sig, handler)
示例7: kill
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGPIPE [as 别名]
def kill(pid, which_signal=None):
# print('killing', pid)
try:
if which_signal is None:
#in some circumstance SIGPIPE can avoid killed message
os.kill(pid, signal.SIGPIPE)
os.kill(pid, signal.SIGKILL)
else:
os.kill(pid, which_signal)
except ProcessLookupError:
pass
示例8: __init__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGPIPE [as 别名]
def __init__(self):
signal(SIGPIPE, SIG_DFL)
self.sock = zmq.Context().socket(zmq.REQ)
self.sock.connect("tcp://127.0.0.1:5556")
示例9: __init__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGPIPE [as 别名]
def __init__(self, url):
signal(SIGPIPE, SIG_DFL)
self.sock = zmq.Context().socket(zmq.REQ)
self.sock.connect(url)
示例10: __init__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGPIPE [as 别名]
def __init__(self):
signal(SIGPIPE, SIG_DFL)
self.sock = zmq.Context().socket(zmq.REQ)
self.sock.connect("tcp://opennmt:5556")
示例11: configure_broken_pipe
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGPIPE [as 别名]
def configure_broken_pipe():
# Use the default behavior (exit quietly) when catching SIGPIPE
signal(SIGPIPE, SIG_DFL)
示例12: output_thread
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGPIPE [as 别名]
def output_thread(log, stdout, stderr, timeout_event, is_alive, quit,
stop_output_event):
""" this function is run in a separate thread. it reads from the
process's stdout stream (a streamreader), and waits for it to claim that
its done """
poller = Poller()
if stdout is not None:
poller.register_read(stdout)
if stderr is not None:
poller.register_read(stderr)
# this is our poll loop for polling stdout or stderr that is ready to
# be read and processed. if one of those streamreaders indicate that it
# is done altogether being read from, we remove it from our list of
# things to poll. when no more things are left to poll, we leave this
# loop and clean up
while poller:
changed = no_interrupt(poller.poll, 0.1)
for f, events in changed:
if events & (POLLER_EVENT_READ | POLLER_EVENT_HUP):
log.debug("%r ready to be read from", f)
done = f.read()
if done:
poller.unregister(f)
elif events & POLLER_EVENT_ERROR:
# for some reason, we have to just ignore streams that have had an
# error. i'm not exactly sure why, but don't remove this until we
# figure that out, and create a test for it
pass
if timeout_event and timeout_event.is_set():
break
if stop_output_event.is_set():
break
# we need to wait until the process is guaranteed dead before closing our
# outputs, otherwise SIGPIPE
alive, _ = is_alive()
while alive:
quit.wait(1)
alive, _ = is_alive()
if stdout:
stdout.close()
if stderr:
stderr.close()
示例13: main
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGPIPE [as 别名]
def main():
args = parser.parse_args()
# Ignore broken pipes
signal(SIGPIPE, SIG_DFL)
log_level = logging.INFO
if args.verbose:
log_level = logging.DEBUG
logging.basicConfig(format='[%(levelname)s:%(name)s] %(asctime)s - %(message)s', level=log_level)
def _handle_messages(message, context):
if args.json:
sys.stdout.flush()
sys.stdout.write(json.dumps(message) + "\n")
sys.stdout.flush()
else:
if args.disable_colors:
logging.debug("Starting normal output.")
payload = "{} {} - {} {}\n".format(
"[{}]".format(datetime.datetime.fromtimestamp(message['data']['seen']).isoformat()),
message['data']['source']['url'],
message['data']['leaf_cert']['subject']['CN'],
"[{}]".format(", ".join(message['data']['leaf_cert']['all_domains'])) if args.full else ""
)
sys.stdout.write(payload)
else:
logging.debug("Starting colored output.")
payload = "{} {} - {} {}\n".format(
termcolor.colored("[{}]".format(datetime.datetime.fromtimestamp(message['data']['seen']).isoformat()), 'cyan', attrs=["bold", ]),
termcolor.colored(message['data']['source']['url'], 'blue', attrs=["bold",]),
termcolor.colored(message['data']['leaf_cert']['subject']['CN'], 'green', attrs=["bold",]),
termcolor.colored("[", 'blue') + "{}".format(
termcolor.colored(", ", 'blue').join(
[termcolor.colored(x, 'white', attrs=["bold",]) for x in message['data']['leaf_cert']['all_domains']]
)
) + termcolor.colored("]", 'blue') if args.full else "",
)
sys.stdout.write(payload)
sys.stdout.flush()
certstream.listen_for_events(_handle_messages, args.url, skip_heartbeats=True)