当前位置: 首页>>代码示例>>Python>>正文


Python signal.SIGPIPE属性代码示例

本文整理汇总了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) 
开发者ID:fitnr,项目名称:twitter_markov,代码行数:20,代码来源:__main__.py

示例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) 
开发者ID:ComparativeGenomicsToolkit,项目名称:Comparative-Annotation-Toolkit,代码行数:13,代码来源:pipeline.py

示例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() 
开发者ID:ComparativeGenomicsToolkit,项目名称:Comparative-Annotation-Toolkit,代码行数:14,代码来源:pipeline.py

示例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) 
开发者ID:skuhl,项目名称:autograder,代码行数:32,代码来源:autograder.py

示例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 
开发者ID:acaceres2176,项目名称:scylla,代码行数:17,代码来源:sh.py

示例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) 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:16,代码来源:fuse_runner.py

示例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 
开发者ID:COMP1511UNSW,项目名称:dcc,代码行数:13,代码来源:start_gdb.py

示例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") 
开发者ID:sld,项目名称:convai-bot-1337,代码行数:6,代码来源:get_qnas.py

示例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) 
开发者ID:sld,项目名称:convai-bot-1337,代码行数:6,代码来源:get_reply.py

示例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") 
开发者ID:sld,项目名称:convai-bot-1337,代码行数:6,代码来源:get_qnas.py

示例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) 
开发者ID:sharkdp,项目名称:shell-functools,代码行数:5,代码来源:command.py

示例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() 
开发者ID:acaceres2176,项目名称:scylla,代码行数:51,代码来源:sh.py

示例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) 
开发者ID:CaliDog,项目名称:certstream-python,代码行数:47,代码来源:cli.py


注:本文中的signal.SIGPIPE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。