本文整理汇总了Python中signal.SIGBREAK属性的典型用法代码示例。如果您正苦于以下问题:Python signal.SIGBREAK属性的具体用法?Python signal.SIGBREAK怎么用?Python signal.SIGBREAK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类signal
的用法示例。
在下文中一共展示了signal.SIGBREAK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_signal_signal
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGBREAK [as 别名]
def test_signal_signal(self):
WORKING_CASES = SUPPORTED_SIGNALS + [6]
WEIRD_CASES = {
6: None,
2: signal.default_int_handler}
for x in WORKING_CASES:
#Ideal handler signature
def a(signum, frame):
return x
ret_val = signal.signal(x, a)
if x not in WEIRD_CASES.keys():
self.assertEqual(ret_val, signal.SIG_DFL)
else:
self.assertEqual(ret_val, WEIRD_CASES[x])
self.assertEqual(a, signal.getsignal(x))
#Strange handler signatures
class KNew(object):
def __call__(self, *args, **kwargs):
pass
a = KNew()
ret_val = signal.signal(signal.SIGBREAK, a)
self.assertEqual(a, signal.getsignal(signal.SIGBREAK))
示例2: __init__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGBREAK [as 别名]
def __init__(self):
# Setup signal fd, this allows signal to behave correctly
if os.name == 'posix':
self.signal_pipe_r, self.signal_pipe_w = os.pipe()
self._set_nonblock(self.signal_pipe_r)
self._set_nonblock(self.signal_pipe_w)
signal.set_wakeup_fd(self.signal_pipe_w)
self._signals_received = collections.deque()
signal.signal(signal.SIGINT, signal.SIG_DFL)
if os.name == 'posix':
signal.signal(signal.SIGCHLD, signal.SIG_DFL)
signal.signal(signal.SIGTERM, self._signal_catcher)
signal.signal(signal.SIGALRM, self._signal_catcher)
signal.signal(signal.SIGHUP, self._signal_catcher)
else:
# currently a noop on window...
signal.signal(signal.SIGTERM, self._signal_catcher)
# FIXME(sileht): should allow to catch signal CTRL_BREAK_EVENT,
# but we to create the child process with CREATE_NEW_PROCESS_GROUP
# to make this work, so current this is a noop for later fix
signal.signal(signal.SIGBREAK, self._signal_catcher)
示例3: test_issue9324
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGBREAK [as 别名]
def test_issue9324(self):
# Updated for issue #10003, adding SIGBREAK
handler = lambda x, y: None
checked = set()
for sig in (signal.SIGABRT, signal.SIGBREAK, signal.SIGFPE,
signal.SIGILL, signal.SIGINT, signal.SIGSEGV,
signal.SIGTERM):
# Set and then reset a handler for signals that work on windows.
# Issue #18396, only for signals without a C-level handler.
if signal.getsignal(sig) is not None:
signal.signal(sig, signal.signal(sig, handler))
checked.add(sig)
# Issue #18396: Ensure the above loop at least tested *something*
self.assertTrue(checked)
with self.assertRaises(ValueError):
signal.signal(-1, handler)
with self.assertRaises(ValueError):
signal.signal(7, handler)
示例4: test_signal_signal
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGBREAK [as 别名]
def test_signal_signal(self):
WORKING_CASES = SUPPORTED_SIGNALS + [6]
WEIRD_CASES = {
6: None,
2: signal.default_int_handler}
for x in WORKING_CASES:
#Ideal handler signature
def a(signum, frame):
return x
ret_val = signal.signal(x, a)
if x not in WEIRD_CASES.keys():
self.assertEqual(ret_val, signal.SIG_DFL)
else:
self.assertEqual(ret_val, WEIRD_CASES[x])
self.assertEqual(a, signal.getsignal(x))
#Strange handler signatures
class KNew(object):
def __call__(self, *args, **kwargs):
pass
a = KNew()
ret_val = signal.signal(signal.SIGBREAK, a)
self.assertEqual(a, signal.getsignal(signal.SIGBREAK))
示例5: terminate
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGBREAK [as 别名]
def terminate(self):
"""Tries to do something saner on Windows that the stdlib.
Windows:
self.detached/CREATE_NEW_PROCESS_GROUP determines what can be used:
- If set, only SIGBREAK can be sent and it is sent to a single process.
- If not set, in theory only SIGINT can be used and *all processes* in
the processgroup receive it. In practice, we just kill the process.
See http://msdn.microsoft.com/library/windows/desktop/ms683155.aspx
The default on Windows is to call TerminateProcess() always, which is not
useful.
On Posix, always send SIGTERM.
"""
try:
if sys.platform == 'win32' and self.detached:
return self.send_signal(signal.CTRL_BREAK_EVENT)
super(Popen, self).terminate()
except OSError:
# The function will throw if the process terminated in-between. Swallow
# this.
pass
示例6: test_issue9324
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGBREAK [as 别名]
def test_issue9324(self):
# Updated for issue #10003, adding SIGBREAK
handler = lambda x, y: None
for sig in (signal.SIGABRT, signal.SIGBREAK, signal.SIGFPE,
signal.SIGILL, signal.SIGINT, signal.SIGSEGV,
signal.SIGTERM):
# Set and then reset a handler for signals that work on windows
signal.signal(sig, signal.signal(sig, handler))
with self.assertRaises(ValueError):
signal.signal(-1, handler)
with self.assertRaises(ValueError):
signal.signal(7, handler)
示例7: test_module_constants
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGBREAK [as 别名]
def test_module_constants(self):
self.assertEqual(signal.NSIG, 23)
self.assertEqual(signal.SIGABRT, 22)
self.assertEqual(signal.SIGBREAK, 21)
self.assertEqual(signal.SIGFPE, 8)
self.assertEqual(signal.SIGILL, 4)
self.assertEqual(signal.SIGINT, 2)
self.assertEqual(signal.SIGSEGV, 11)
self.assertEqual(signal.SIGTERM, 15)
self.assertEqual(signal.SIG_DFL, 0)
self.assertEqual(signal.SIG_IGN, 1)
示例8: kill
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGBREAK [as 别名]
def kill(self, sig):
'''Sends a Unix signal to the subprocess.
Use constants from the :mod:`signal` module to specify which signal.
'''
if sys.platform == 'win32':
if sig in [signal.SIGINT, signal.CTRL_C_EVENT]:
sig = signal.CTRL_C_EVENT
elif sig in [signal.SIGBREAK, signal.CTRL_BREAK_EVENT]:
sig = signal.CTRL_BREAK_EVENT
else:
sig = signal.SIGTERM
os.kill(self.proc.pid, sig)
示例9: test_captureSIGBREAK
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGBREAK [as 别名]
def test_captureSIGBREAK(self):
"""
ReactorBase's SIGBREAK handler saves the value of SIGBREAK to the
_exitSignal attribute.
"""
if not hasattr(signal, "SIGBREAK"):
raise SkipTest("signal module does not have SIGBREAK")
reactor = TestSpySignalCapturingReactor()
reactor.sigBreak(signal.SIGBREAK, None)
self.assertEquals(signal.SIGBREAK, reactor._exitSignal)
示例10: kill
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGBREAK [as 别名]
def kill(self, sig):
'''Sends a Unix signal to the subprocess.
Use constants from the :mod:`signal` module to specify which signal.
'''
if sys.platform == 'win32':
if sig in [signal.SIGINT, signal.CTRL_C_EVENT]:
sig = signal.CTRL_C_EVENT
elif sig in [signal.SIGBREAK, signal.CTRL_BREAK_EVENT]:
sig = signal.CTRL_BREAK_EVENT
else:
sig = signal.SIGTERM
os.kill(self.proc.pid, sig)
示例11: exec_python
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGBREAK [as 别名]
def exec_python(args):
"""Executes a python process, replacing the current process if possible.
On Windows, it returns the child process code. The caller must exit at the
earliest opportunity.
"""
cmd = [sys.executable] + args
if sys.platform not in ('cygwin', 'win32'):
os.execv(cmd[0], cmd)
return 1
try:
# On Windows, we cannot sanely exec() so shell out the child process
# instead. But we need to forward any signal received that the bot may care
# about. This means processes accumulate, sadly.
# TODO(maruel): If stdin closes, it tells the child process that the parent
# process died.
proc = subprocess42.Popen(cmd, detached=True, stdin=subprocess42.PIPE)
def handler(sig, _):
logging.info('Got signal %s', sig)
# Always send SIGTERM, which is properly translated.
proc.send_signal(signal.SIGTERM)
sig = signal.SIGBREAK if sys.platform == 'win32' else signal.SIGTERM
with subprocess42.set_signal_handler([sig], handler):
proc.wait()
return proc.returncode
except Exception as e:
logging.exception('failed to start: %s', e)
# Swallow the exception.
return 1
示例12: term_signal
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGBREAK [as 别名]
def term_signal():
"""Gets the term signal for the os."""
if os.name == 'nt':
return signal.SIGBREAK
else:
return signal.SIGTERM
示例13: _execute
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGBREAK [as 别名]
def _execute(path, argv=None, environ=None):
""" Executes an external search command.
:param path: Path to the external search command.
:type path: unicode
:param argv: Argument list.
:type argv: list or tuple
The arguments to the child process should start with the name of the command being run, but this is not
enforced. A value of :const:`None` specifies that the base name of path name :param:`path` should be used.
:param environ: A mapping which is used to define the environment variables for the new process.
:type environ: dict or None.
This mapping is used instead of the current process’s environment. A value of :const:`None` specifies that
the :data:`os.environ` mapping should be used.
:return: None
"""
search_path = os.getenv('PATH') if environ is None else environ.get('PATH')
found = ExternalSearchCommand._search_path(path, search_path)
if found is None:
raise ValueError('Cannot find command on path: {}'.format(path))
path = found
logger.debug('starting command="%s", arguments=%s', path, argv)
def terminate(signal_number, frame):
sys.exit('External search command is terminating on receipt of signal={}.'.format(signal_number))
def terminate_child():
if p.pid is not None and p.returncode is None:
logger.debug('terminating command="%s", arguments=%d, pid=%d', path, argv, p.pid)
os.kill(p.pid, CTRL_BREAK_EVENT)
p = Popen(argv, executable=path, env=environ, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
atexit.register(terminate_child)
signal(SIGBREAK, terminate)
signal(SIGINT, terminate)
signal(SIGTERM, terminate)
logger.debug('started command="%s", arguments=%s, pid=%d', path, argv, p.pid)
p.wait()
logger.debug('finished command="%s", arguments=%s, pid=%d, returncode=%d', path, argv, p.pid, p.returncode)
if p.returncode != 0:
sys.exit(p.returncode)
示例14: _execute
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGBREAK [as 别名]
def _execute(path, argv=None, environ=None):
""" Executes an external search command.
:param path: Path to the external search command.
:type path: unicode
:param argv: Argument list.
:type argv: list or tuple
The arguments to the child process should start with the name of the command being run, but this is not
enforced. A value of :const:`None` specifies that the base name of path name :param:`path` should be used.
:param environ: A mapping which is used to define the environment variables for the new process.
:type environ: dict or None.
This mapping is used instead of the current process’s environment. A value of :const:`None` specifies that
the :data:`os.environ` mapping should be used.
:return: None
"""
search_path = os.getenv('PATH') if environ is None else environ.get('PATH')
found = ExternalSearchCommand._search_path(path, search_path)
if found is None:
raise ValueError('Cannot find command on path: {}'.format(path))
path = found
logger.debug('starting command="%s", arguments=%s', path, argv)
def terminate(signal_number, frame):
sys.exit('External search command is terminating on receipt of signal={}.'.format(signal_number))
def terminate_child():
if p.pid is not None and p.returncode is None:
logger.debug('terminating command="%s", arguments=%d, pid=%d', path, argv, p.pid)
os.kill(p.pid, CTRL_BREAK_EVENT)
p = Popen(argv, executable=path, env=environ, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
atexit.register(terminate_child)
signal(SIGBREAK, terminate)
signal(SIGINT, terminate)
signal(SIGTERM, terminate)
logger.debug('started command="%s", arguments=%s, pid=%d', path, argv, p.pid)
p.wait()
logger.debug('finished command="%s", arguments=%s, pid=%d, returncode=%d', path, argv, p.pid, p.returncode)
if p.returncode != 0:
sys.exit(p.returncode)
示例15: _execute
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIGBREAK [as 别名]
def _execute(path, argv=None, environ=None):
""" Executes an external search command.
:param path: Path to the external search command.
:type path: unicode
:param argv: Argument list.
:type argv: list or tuple
The arguments to the child process should start with the name of the command being run, but this is not
enforced. A value of :const:`None` specifies that the base name of path name :param:`path` should be used.
:param environ: A mapping which is used to define the environment variables for the new process.
:type environ: dict or None.
This mapping is used instead of the current process’s environment. A value of :const:`None` specifies that
the :data:`os.environ` mapping should be used.
:return: None
"""
search_path = os.getenv('PATH') if environ is None else environ.get('PATH')
found = ExternalSearchCommand._search_path(path, search_path)
if found is None:
raise ValueError('Cannot find command on path: {}'.format(path))
path = found
logger.debug('starting command="%s", arguments=%s', path, argv)
def terminate(signal_number, frame):
sys.exit('External search command is terminating on receipt of signal={}.'.format(signal_number))
def terminate_child():
if p.pid is not None and p.returncode is None:
logger.debug('terminating command="%s", arguments=%d, pid=%d', path, argv, p.pid)
os.kill(p.pid, CTRL_BREAK_EVENT)
p = Popen(argv, executable=path, env=environ, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
atexit.register(terminate_child)
signal(SIGBREAK, terminate)
signal(SIGINT, terminate)
signal(SIGTERM, terminate)
logger.debug('started command="%s", arguments=%s, pid=%d', path, argv, p.pid)
p.wait()
logger.debug('finished command="%s", arguments=%s, pid=%d, returncode=%d', path, argv, p.pid, p.returncode)
sys.exit(p.returncode)