本文整理匯總了Python中signal.Signals方法的典型用法代碼示例。如果您正苦於以下問題:Python signal.Signals方法的具體用法?Python signal.Signals怎麽用?Python signal.Signals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類signal
的用法示例。
在下文中一共展示了signal.Signals方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_results_message
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import Signals [as 別名]
def get_results_message(results: dict) -> Tuple[str, str]:
"""Return a user-friendly message and error corresponding to the process's return code."""
stdout, returncode = results["stdout"], results["returncode"]
msg = f"Your eval job has completed with return code {returncode}"
error = ""
if returncode is None:
msg = "Your eval job has failed"
error = stdout.strip()
elif returncode == 128 + SIGKILL:
msg = "Your eval job timed out or ran out of memory"
elif returncode == 255:
msg = "Your eval job has failed"
error = "A fatal NsJail error occurred"
else:
# Try to append signal's name if one exists
try:
name = Signals(returncode - 128).name
msg = f"{msg} ({name})"
except ValueError:
pass
return msg, error
示例2: __str__
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import Signals [as 別名]
def __str__(self):
if self.returncode and self.returncode < 0:
try:
return "Command '%s' died with %r." % (
self.cmd,
signal.Signals(-self.returncode),
)
except ValueError:
return "Command '%s' died with unknown signal %d." % (
self.cmd,
-self.returncode,
)
else:
return "Command '%s' returned non-zero exit status %d." % (
self.cmd,
self.returncode,
)
示例3: terminate_agents
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import Signals [as 別名]
def terminate_agents(
cls,
*subprocesses: subprocess.Popen,
signal: signal.Signals = signal.SIGINT,
timeout: int = 10,
) -> None:
"""
Terminate agent subprocesses.
Run from agent's directory.
:param subprocesses: the subprocesses running the agents
:param signal: the signal for interuption
:param timeout: the timeout for interuption
"""
if not subprocesses:
subprocesses = tuple(cls.subprocesses)
for process in subprocesses:
sigint_crossplatform(process)
for process in subprocesses:
process.wait(timeout=timeout)
示例4: _get_exitcode_name
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import Signals [as 別名]
def _get_exitcode_name(exitcode):
if sys.platform == "win32":
# The exitcode are unreliable on windows (see bpo-31863).
# For this case, return UNKNOWN
return "UNKNOWN"
if exitcode < 0:
try:
import signal
if sys.version_info > (3, 5):
return signal.Signals(-exitcode).name
# construct an inverse lookup table
for v, k in signal.__dict__.items():
if (v.startswith('SIG') and not v.startswith('SIG_') and
k == -exitcode):
return v
except ValueError:
return "UNKNOWN"
elif exitcode != 255:
# The exitcode are unreliable on forkserver were 255 is always returned
# (see bpo-30589). For this case, return UNKNOWN
return "EXIT"
return "UNKNOWN"
示例5: signal_handler
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import Signals [as 別名]
def signal_handler(sig, frame):
global program_running
log.warning("Got signal, " + signal.Signals(sig).name + " terminating!")
print("Got signal,", signal.Signals(sig).name, "terminating!")
try:
device.__exit__()
log.info("Removed uinput device")
print("Removed uinput device")
except SystemExit:
sys.exit(0)
except Exception as e:
print("Could not remove uinput device:",e)
log.info("Could not remove uinput device:",e)
# pid_handler.remove_pid()
log.info("----------------------EXITING-----------------------")
print("Exiting")
program_running = False
sys.exit(0)
示例6: exit_handler
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import Signals [as 別名]
def exit_handler(signum, frame):
log.info("Received %s, canceling jobs and exiting.", signal.Signals(signum).name)
schedule.clear()
exit()
############################################################
# MAIN
############################################################
示例7: status_name
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import Signals [as 別名]
def status_name(self) -> str:
return signal.Signals(self.status).name
示例8: __enter__
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import Signals [as 別名]
def __enter__(self):
self.signal_received = {}
self.old_handlers = {}
for sig in self.sigs:
self.signal_received[sig] = False
self.old_handlers[sig] = signal.getsignal(sig)
def handler(s, frame):
self.signal_received[sig] = (s, frame)
# Note: in Python 3.5, you can use signal.Signals(sig).name
logging.info('Signal %s received. Delaying KeyboardInterrupt.' % sig)
self.old_handlers[sig] = signal.getsignal(sig)
signal.signal(sig, handler)
示例9: signal_handler
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import Signals [as 別名]
def signal_handler(signal_number, frame):
sig_name = signal.Signals(signal_number).name
logger.info(f'Captured signal number {signal_number}. Name: {sig_name}')
示例10: __enter__
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import Signals [as 別名]
def __enter__(self):
self.signal_received = {}
self.old_handlers = {}
for sig in self.sigs:
self.signal_received[sig] = False
self.old_handlers[sig] = signal.getsignal(sig)
def handler(s, frame):
self.signal_received[sig] = (s, frame)
# Note: in Python 3.5, you can use signal.Signals(sig).name
self.old_handlers[sig] = signal.getsignal(sig)
signal.signal(sig, handler)
示例11: _add_signal_handler
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import Signals [as 別名]
def _add_signal_handler(self, signum: Signals, handler: Callable[[Signals], None]) -> None:
try:
self.loop.add_signal_handler(signum, partial(handler, signum))
except NotImplementedError: # pragma: no cover
logger.debug('Windows does not support adding a signal handler to an eventloop')
示例12: handle_sig
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import Signals [as 別名]
def handle_sig(self, signum: Signals) -> None:
sig = Signals(signum)
logger.info(
'shutdown on %s ◆ %d jobs complete ◆ %d failed ◆ %d retries ◆ %d ongoing to cancel',
sig.name,
self.jobs_complete,
self.jobs_failed,
self.jobs_retried,
len(self.tasks),
)
for t in self.tasks:
if not t.done():
t.cancel()
self.main_task and self.main_task.cancel()
self.on_stop and self.on_stop(sig)
示例13: test_enums
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import Signals [as 別名]
def test_enums(self):
for name in dir(signal):
sig = getattr(signal, name)
if name in {'SIG_DFL', 'SIG_IGN'}:
self.assertIsInstance(sig, signal.Handlers)
elif name in {'SIG_BLOCK', 'SIG_UNBLOCK', 'SIG_SETMASK'}:
self.assertIsInstance(sig, signal.Sigmasks)
elif name.startswith('SIG') and not name.startswith('SIG_'):
self.assertIsInstance(sig, signal.Signals)
elif name.startswith('CTRL_'):
self.assertIsInstance(sig, signal.Signals)
self.assertEqual(sys.platform, "win32")
示例14: test_sigpending
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import Signals [as 別名]
def test_sigpending(self):
code = """if 1:
import os
import signal
def handler(signum, frame):
1/0
signum = signal.SIGUSR1
signal.signal(signum, handler)
signal.pthread_sigmask(signal.SIG_BLOCK, [signum])
os.kill(os.getpid(), signum)
pending = signal.sigpending()
for sig in pending:
assert isinstance(sig, signal.Signals), repr(pending)
if pending != {signum}:
raise Exception('%s != {%s}' % (pending, signum))
try:
signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum])
except ZeroDivisionError:
pass
else:
raise Exception("ZeroDivisionError not raised")
"""
assert_python_ok('-c', code)
示例15: test_sigwait
# 需要導入模塊: import signal [as 別名]
# 或者: from signal import Signals [as 別名]
def test_sigwait(self):
self.wait_helper(signal.SIGALRM, '''
def test(signum):
signal.alarm(1)
received = signal.sigwait([signum])
assert isinstance(received, signal.Signals), received
if received != signum:
raise Exception('received %s, not %s' % (received, signum))
''')