當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。