本文整理汇总了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)
示例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)
示例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()
示例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))
示例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)
示例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))
示例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))
示例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)
示例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))
示例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
示例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