當前位置: 首頁>>代碼示例>>Python>>正文


Python signal.html方法代碼示例

本文整理匯總了Python中signal.html方法的典型用法代碼示例。如果您正苦於以下問題:Python signal.html方法的具體用法?Python signal.html怎麽用?Python signal.html使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在signal的用法示例。


在下文中一共展示了signal.html方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: stop

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import html [as 別名]
def stop(self, signal=None, frame=None):
        """Manage the shutdown process of the worker.

        This function has two purposes:

            1. Cancel all the futures created.
            2. And close all the database connections
               opened by Django. Even though we cancel the connections
               for every execution of the callback, we want to be sure
               that all the database connections are closed
               in this process.

        Exits with code 0 for a clean exit.

        :param signal: Needed for `signal.signal <https://docs.python.org/3/library/signal.html#signal.signal>`_  # noqa
        :param frame: Needed for `signal.signal <https://docs.python.org/3/library/signal.html#signal.signal>`_  # noqa
        """
        run_middleware_hook("pre_worker_stop", self._subscriptions)
        for future in self._futures:
            future.cancel()

        run_middleware_hook("post_worker_stop")
        sys.exit(0) 
開發者ID:mercadona,項目名稱:rele,代碼行數:25,代碼來源:worker.py

示例2: signal_handler

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import html [as 別名]
def signal_handler(signal, frame=None):
    state_machine_execution_engine = core_singletons.state_machine_execution_engine
    core_singletons.shut_down_signal = signal

    # in this case the print is on purpose to see more easily if the interrupt signal reached the thread
    print(_("Signal '{}' received.\nExecution engine will be stopped and program will be shutdown!").format(
        SIGNALS_TO_NAMES_DICT.get(signal, "[unknown]")))

    # close gui properly
    gui_singletons.main_window_controller.get_controller('menu_bar_controller').on_quit_activate(None)

    post_gui_destruction()

    logging.shutdown()

    # Do not use sys.exit() in signal handler:
    # http://thushw.blogspot.de/2010/12/python-dont-use-sysexit-inside-signal.html
    # noinspection PyProtectedMember
    os._exit(0) 
開發者ID:DLR-RM,項目名稱:RAFCON,代碼行數:21,代碼來源:start.py

示例3: command

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import html [as 別名]
def command(self):
        setproctitle('taskd')
        self.basic_setup()
        self.keep_running = True
        self.restart_when_done = False
        base.log.info('Starting taskd, pid %s' % os.getpid())
        signal.signal(signal.SIGHUP, self.graceful_restart)
        signal.signal(signal.SIGTERM, self.graceful_stop)
        signal.signal(signal.SIGUSR1, self.log_current_task)
        # restore default behavior of not interrupting system calls
        # see http://docs.python.org/library/signal.html#signal.siginterrupt
        # and http://linux.die.net/man/3/siginterrupt
        signal.siginterrupt(signal.SIGHUP, False)
        signal.siginterrupt(signal.SIGTERM, False)
        signal.siginterrupt(signal.SIGUSR1, False)
        self.worker() 
開發者ID:apache,項目名稱:allura,代碼行數:18,代碼來源:taskd.py

示例4: _worker_loop

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import html [as 別名]
def _worker_loop(dataset, index_queue, data_queue, collate_fn, seed, init_fn, worker_id):
    global _use_shared_memory
    _use_shared_memory = True

    # Intialize C side signal handlers for SIGBUS and SIGSEGV. Python signal
    # module's handlers are executed after Python returns from C low-level
    # handlers, likely when the same fatal signal happened again already.
    # https://docs.python.org/3/library/signal.html Sec. 18.8.1.1
    _set_worker_signal_handlers()

    torch.set_num_threads(1)
    torch.manual_seed(seed)
    np.random.seed(seed)

    if init_fn is not None:
        init_fn(worker_id)

    while True:
        r = index_queue.get()
        if r is None:
            break
        idx, batch_indices = r
        try:
            samples = collate_fn([dataset[i] for i in batch_indices])
        except Exception:
            data_queue.put((idx, ExceptionWrapper(sys.exc_info())))
        else:
            data_queue.put((idx, samples)) 
開發者ID:XiaLiPKU,項目名稱:EMANet,代碼行數:30,代碼來源:dataloader.py

示例5: init

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import html [as 別名]
def init():
    """Register cleanup handler."""
    logger.debug("Registering cleanup handler")

    global __cleanup_done
    __cleanup_done = False

    # Will be OS-specific, see https://docs.python.org/2/library/signal.html
    atexit.register(cleanup_handler)
    signal.signal(signal.SIGTERM, cleanup_handler)
    if sys.platform == "darwin" or "linux" in sys.platform:
        # SIGHUP is not available on Windows
        signal.signal(signal.SIGHUP, cleanup_handler) 
開發者ID:mozilla,項目名稱:iris,代碼行數:15,代碼來源:cleanup.py

示例6: _worker_loop

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import html [as 別名]
def _worker_loop(
    dataset, index_queue, data_queue, collate_fn, seed, init_fn, worker_id
):
    global _use_shared_memory
    _use_shared_memory = True

    # Intialize C side signal handlers for SIGBUS and SIGSEGV. Python signal
    # module's handlers are executed after Python returns from C low-level
    # handlers, likely when the same fatal signal happened again already.
    # https://docs.python.org/3/library/signal.html Sec. 18.8.1.1
    #  C._set_worker_signal_handlers()

    torch.set_num_threads(1)
    torch.manual_seed(seed)

    if init_fn is not None:
        init_fn(worker_id)

    try:
        dataset.init()
    except AttributeError:
        pass

    while True:
        r = index_queue.get()

        if r is None:
            break

        idx, batch_indices = r
        try:
            samples = collate_fn([dataset[i] for i in batch_indices])
        except Exception:
            data_queue.put((idx, ExceptionWrapper(sys.exc_info())))
        else:
            data_queue.put((idx, samples)) 
開發者ID:ethnhe,項目名稱:PVN3D,代碼行數:38,代碼來源:persistent_dataloader.py

示例7: _worker_loop

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import html [as 別名]
def _worker_loop(
        dataset, index_queue, data_queue, collate_fn, seed, init_fn, worker_id
):
    global _use_shared_memory
    _use_shared_memory = True

    # Intialize C side signal handlers for SIGBUS and SIGSEGV. Python signal
    # module's handlers are executed after Python returns from C low-level
    # handlers, likely when the same fatal signal happened again already.
    # https://docs.python.org/3/library/signal.html Sec. 18.8.1.1
    #  C._set_worker_signal_handlers()

    torch.set_num_threads(1)
    torch.manual_seed(seed)

    if init_fn is not None:
        init_fn(worker_id)

    try:
        dataset.init()
    except AttributeError:
        pass

    while True:
        r = index_queue.get()

        if r is None:
            break

        idx, batch_indices = r
        try:
            samples = collate_fn([dataset[i] for i in batch_indices])
        except Exception:
            data_queue.put((idx, ExceptionWrapper(sys.exc_info())))
        else:
            data_queue.put((idx, samples)) 
開發者ID:sfu-gruvi-3dv,項目名稱:sanet_relocal_demo,代碼行數:38,代碼來源:persistent_dataloader.py

示例8: init

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import html [as 別名]
def init():
    """Register cleanup handler"""

    # print "Registering cleanup handler"

    global __cleanup_done
    __cleanup_done = False

    # Will be OS-specific, see https://docs.python.org/2/library/signal.html
    atexit.register(cleanup_handler)
    signal.signal(signal.SIGTERM, cleanup_handler)
    if sys.platform == "darwin" or "linux" in sys.platform:
        # SIGHUP is not available on Windows
        signal.signal(signal.SIGHUP, cleanup_handler) 
開發者ID:mozilla,項目名稱:tls-canary,代碼行數:16,代碼來源:cleanup.py

示例9: _worker_loop

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import html [as 別名]
def _worker_loop(dataset, index_queue, data_queue, collate_fn, seed, init_fn, worker_id):
    global _use_shared_memory
    _use_shared_memory = True

    # Intialize C side signal handlers for SIGBUS and SIGSEGV. Python signal
    # module's handlers are executed after Python returns from C low-level
    # handlers, likely when the same fatal signal happened again already.
    # https://docs.python.org/3/library/signal.html Sec. 18.8.1.1
    _set_worker_signal_handlers()

    torch.set_num_threads(1)
    random.seed(seed)
    torch.manual_seed(seed)

    if init_fn is not None:
        init_fn(worker_id)

    while True:
        r = index_queue.get()
        if r is None:
            break
        idx, batch_indices = r
        try:
            samples = collate_fn([dataset[i] for i in batch_indices])
        except Exception:
            data_queue.put((idx, ExceptionWrapper(sys.exc_info())))
        else:
            data_queue.put((idx, samples)) 
開發者ID:astorfi,項目名稱:3D-convolutional-speaker-recognition-pytorch,代碼行數:30,代碼來源:loader_fn.py

示例10: _worker_loop

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import html [as 別名]
def _worker_loop(dataset, index_queue, data_queue, collate_fn, init_fn, worker_id):
    global _use_shared_memory
    _use_shared_memory = True

    # Intialize C side signal handlers for SIGBUS and SIGSEGV. Python signal
    # module's handlers are executed after Python returns from C low-level
    # handlers, likely when the same fatal signal happened again already.
    # https://docs.python.org/3/library/signal.html Sec. 18.8.1.1
    _set_worker_signal_handlers()

    torch.set_num_threads(1)

    if init_fn is not None:
        init_fn(worker_id)

    watchdog = ManagerWatchdog()

    while True:
        try:
            r = index_queue.get(timeout=MANAGER_STATUS_CHECK_INTERVAL)
        except queue.Empty:
            if watchdog.is_alive():
                continue
            else:
                break
        if r is None:
            break
        idx, batch_indices = r
        try:
            samples = collate_fn([dataset[i] for i in batch_indices])
        except Exception:
            data_queue.put((idx, ExceptionWrapper(sys.exc_info())))
        else:
            data_queue.put((idx, samples))
            del samples 
開發者ID:namisan,項目名稱:mt-dnn,代碼行數:37,代碼來源:dataloader.py

示例11: parse_args

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import html [as 別名]
def parse_args() -> Tuple[argparse.Namespace, List[str]]:
    usage = dedent(
        """Scalene: a high-precision CPU and memory profiler.
        https://github.com/emeryberger/scalene
        % scalene yourprogram.py
        """
    )
    parser = argparse.ArgumentParser(
        prog="scalene",
        description=usage,
        formatter_class=argparse.RawTextHelpFormatter,
        allow_abbrev=False,
    )
    parser.add_argument("prog", type=str, help="program to be profiled")
    parser.add_argument(
        "--outfile",
        type=str,
        default=None,
        help="file to hold profiler output (default: stdout)",
    )
    parser.add_argument(
        "--html",
        dest="html",
        action="store_const",
        const=True,
        default=False,
        help="output as HTML (default: text)",
    )
    parser.add_argument(
        "--profile-interval",
        type=float,
        default=float("inf"),
        help="output profiles every so many seconds.",
    )
    parser.add_argument(
        "--wallclock",
        dest="wallclock",
        action="store_const",
        const=True,
        default=False,
        help="use wall clock time (default: virtual time)",
    )
    parser.add_argument(
        "--cpu-only",
        dest="cpuonly",
        action="store_const",
        const=True,
        default=False,
        help="only profile CPU time (default: profile CPU, memory, and copying)",
    )
    # the PID of the profiling process (for internal use only)
    parser.add_argument(
        "--pid", type=int, default=int(os.getpid()), help=argparse.SUPPRESS
    )
    # Parse out all Scalene arguments and jam the remaining ones into argv.
    # https://stackoverflow.com/questions/35733262/is-there-any-way-to-instruct-argparse-python-2-7-to-remove-found-arguments-fro
    args, left = parser.parse_known_args()
    return args, left 
開發者ID:emeryberger,項目名稱:scalene,代碼行數:60,代碼來源:scalene.py


注:本文中的signal.html方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。