本文整理汇总了Python中signal.SIG_IGN属性的典型用法代码示例。如果您正苦于以下问题:Python signal.SIG_IGN属性的具体用法?Python signal.SIG_IGN怎么用?Python signal.SIG_IGN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类signal
的用法示例。
在下文中一共展示了signal.SIG_IGN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_IGN [as 别名]
def __init__(self, default_handler):
self.called = False
self.original_handler = default_handler
if isinstance(default_handler, int):
if default_handler == signal.SIG_DFL:
# Pretend it's signal.default_int_handler instead.
default_handler = signal.default_int_handler
elif default_handler == signal.SIG_IGN:
# Not quite the same thing as SIG_IGN, but the closest we
# can make it: do nothing.
def default_handler(unused_signum, unused_frame):
pass
else:
raise TypeError("expected SIGINT signal handler to be "
"signal.SIG_IGN, signal.SIG_DFL, or a "
"callable object")
self.default_handler = default_handler
示例2: parallel_map
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_IGN [as 别名]
def parallel_map(function, iterable):
"""Calls a function for every element in an iterable using multiple cores."""
if FORCE_DISABLE_MULTIPROCESSING:
return [function(*args) for args in iterable]
original_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)
num_threads = mp.cpu_count() * 2
pool = mp.Pool(processes=num_threads)
signal.signal(signal.SIGINT, original_sigint_handler)
p = pool.map_async(_function_wrapper, ((function, args) for args in iterable))
try:
results = p.get(0xFFFFFFFF)
except KeyboardInterrupt:
pool.terminate()
raise
pool.close()
return results
示例3: __init__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_IGN [as 别名]
def __init__(self, msg_queue, db_interface):
self.response_queue = msg_queue
self.log = logging.getLogger("Main.LinkAggregator")
try:
signal.signal(signal.SIGINT, signal.SIG_IGN)
except ValueError:
self.log.warning("Cannot configure job fetcher task to ignore SIGINT. May be an issue.")
# LRU Cache with a maxsize of 1 million, and a TTL of 6 hours
self.seen = cachetools.TTLCache(maxsize=1000 * 1000, ttl=60 * 60 * 6)
self.queue_items = 0
self.link_count = 0
self.amqpUpdateCount = 0
self.deathCounter = 0
self.batched_links = []
self.pending_upserts = []
self.db_int = db_interface
self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=6)
self.check_init_func()
示例4: __init__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_IGN [as 别名]
def __init__(self, default_handler):
self.called = False
self.original_handler = default_handler
if isinstance(default_handler, (int, long)):
if default_handler == signal.SIG_DFL:
# Pretend it's signal.default_int_handler instead.
default_handler = signal.default_int_handler
elif default_handler == signal.SIG_IGN:
# Not quite the same thing as SIG_IGN, but the closest we
# can make it: do nothing.
def default_handler(unused_signum, unused_frame):
pass
else:
raise TypeError("expected SIGINT signal handler to be "
"signal.SIG_IGN, signal.SIG_DFL, or a "
"callable object")
self.default_handler = default_handler
示例5: testSecondInterrupt
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_IGN [as 别名]
def testSecondInterrupt(self):
# Can't use skipIf decorator because the signal handler may have
# been changed after defining this method.
if signal.getsignal(signal.SIGINT) == signal.SIG_IGN:
self.skipTest("test requires SIGINT to not be ignored")
result = unittest.TestResult()
unittest.installHandler()
unittest.registerResult(result)
def test(result):
pid = os.getpid()
os.kill(pid, signal.SIGINT)
result.breakCaught = True
self.assertTrue(result.shouldStop)
os.kill(pid, signal.SIGINT)
self.fail("Second KeyboardInterrupt not raised")
try:
test(result)
except KeyboardInterrupt:
pass
else:
self.fail("Second KeyboardInterrupt not raised")
self.assertTrue(result.breakCaught)
示例6: testHandlerReplacedButCalled
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_IGN [as 别名]
def testHandlerReplacedButCalled(self):
# Can't use skipIf decorator because the signal handler may have
# been changed after defining this method.
if signal.getsignal(signal.SIGINT) == signal.SIG_IGN:
self.skipTest("test requires SIGINT to not be ignored")
# If our handler has been replaced (is no longer installed) but is
# called by the *new* handler, then it isn't safe to delay the
# SIGINT and we should immediately delegate to the default handler
unittest.installHandler()
handler = signal.getsignal(signal.SIGINT)
def new_handler(frame, signum):
handler(frame, signum)
signal.signal(signal.SIGINT, new_handler)
try:
pid = os.getpid()
os.kill(pid, signal.SIGINT)
except KeyboardInterrupt:
pass
else:
self.fail("replaced but delegated handler doesn't raise interrupt")
示例7: _import_mp
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_IGN [as 别名]
def _import_mp():
global Process, Queue, Pool, Event, Value, Array
try:
from multiprocessing import Manager, Process
#prevent the server process created in the manager which holds Python
#objects and allows other processes to manipulate them using proxies
#to interrupt on SIGINT (keyboardinterrupt) so that the communication
#channel between subprocesses and main process is still usable after
#ctrl+C is received in the main process.
old=signal.signal(signal.SIGINT, signal.SIG_IGN)
m = Manager()
#reset it back so main process will receive a KeyboardInterrupt
#exception on ctrl+c
signal.signal(signal.SIGINT, old)
Queue, Pool, Event, Value, Array = (
m.Queue, m.Pool, m.Event, m.Value, m.Array
)
except ImportError:
warn("multiprocessing module is not available, multiprocess plugin "
"cannot be used", RuntimeWarning)
示例8: _process_wrapper
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_IGN [as 别名]
def _process_wrapper(exit_event, proc_name, function, agent_name=None):
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGHUP, _mutate_config)
if agent_name:
process_title = 'octavia-driver-agent - {} -- {}'.format(
proc_name, agent_name)
else:
process_title = 'octavia-driver-agent - {}'.format(proc_name)
setproctitle.setproctitle(process_title)
while not exit_event.is_set():
try:
function(exit_event)
except Exception as e:
if agent_name:
LOG.exception('Provider agent "%s" raised exception: %s. '
'Restarting the "%s" provider agent.',
agent_name, str(e), agent_name)
else:
LOG.exception('%s raised exception: %s. '
'Restarting %s.',
proc_name, str(e), proc_name)
time.sleep(1)
continue
break
示例9: accept_invitation_and_play
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_IGN [as 别名]
def accept_invitation_and_play(server_url, auth, invitation_id, bot_cls, finished):
# make sure this process doesn't react to interrupt signals
signal.signal(signal.SIGTERM, signal.SIG_IGN)
signal.signal(signal.SIGINT, signal.SIG_IGN)
print('[{}] Accepting invitation {}.'.format(datetime.now(), invitation_id))
server = RBCServer(server_url, auth)
game_id = server.accept_invitation(invitation_id)
print('[{}] Invitation {} accepted. Playing game {}.'.format(datetime.now(), invitation_id, game_id))
try:
play_remote_game(server_url, game_id, auth, bot_cls())
print('[{}] Finished game {}'.format(datetime.now(), game_id))
except:
print('[{}] Fatal error in game {}:'.format(datetime.now(), game_id))
traceback.print_exc()
server.error_resign(game_id)
finally:
server.finish_invitation(invitation_id)
finished.value = True
示例10: __init__
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_IGN [as 别名]
def __init__(self, task_name, manager, config, timer, base_dir, backup_dir, **kwargs):
self.task_name = task_name
self.manager = manager
self.config = config
self.timer = timer
self.base_dir = base_dir
self.backup_dir = backup_dir
self.args = kwargs
self.verbose = self.config.verbose
self.runnning = False
self.stopped = False
self.completed = False
self.exit_code = 255
self.thread_count = None
self.cpu_count = cpu_count()
self.compression_method = 'none'
self.compression_supported = ['none']
self.timer_name = self.__class__.__name__
signal(SIGINT, SIG_IGN)
signal(SIGTERM, self.close)
示例11: init_worker
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_IGN [as 别名]
def init_worker(num_instances, kernel_h, kernel_w, pad, stride, indices, pdfs):
global g_num_instances
g_num_instances = num_instances
global g_kernel_h
g_kernel_h = kernel_h
global g_kernel_w
g_kernel_w = kernel_w
global g_pad
g_pad = pad
global g_stride
g_stride = stride
global g_indices
g_indices = indices
global g_pdfs
g_pdfs = pdfs
signal.signal(signal.SIGINT, signal.SIG_IGN)
np.random.seed(None)
示例12: _init_child
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_IGN [as 别名]
def _init_child(tmpdir):
'''
Initialize new process from multiprocessing module's Pool.
:param tmpdir: Path of local staging area.
'''
signal.signal(signal.SIGINT, signal.SIG_IGN)
# .................................for each process, create a isolated temp folder
proc_dir = os.path.join(tmpdir, current_process().name)
if not os.path.isdir(proc_dir):
os.mkdir(proc_dir)
示例13: init
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_IGN [as 别名]
def init():
signal.signal(signal.SIGINT, signal.SIG_IGN)
示例14: signal_handler
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_IGN [as 别名]
def signal_handler(self, signum, *frame):
ED2.callFromThread(self.dispatch)
if self.previous_handler not in (SIG_IGN, SIG_DFL):
try:
self.previous_handler(signum, *frame)
except:
dump_exception('Signal: unhandled exception in signal chain')
示例15: mask_sigint
# 需要导入模块: import signal [as 别名]
# 或者: from signal import SIG_IGN [as 别名]
def mask_sigint():
"""
Returns:
If called in main thread, returns a context where ``SIGINT`` is ignored, and yield True.
Otherwise yield False.
"""
if is_main_thread():
sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)
yield True
signal.signal(signal.SIGINT, sigint_handler)
else:
yield False