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


Python signal.SIG_IGN屬性代碼示例

本文整理匯總了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 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:19,代碼來源:signals.py

示例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 
開發者ID:GoogleCloudPlatform,項目名稱:cloudml-samples,代碼行數:20,代碼來源:data-extractor.py

示例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() 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:26,代碼來源:UrlUpserter.py

示例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 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:signals.py

示例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) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:test_break.py

示例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") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:24,代碼來源:test_break.py

示例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) 
開發者ID:singhj,項目名稱:locality-sensitive-hashing,代碼行數:22,代碼來源:multiprocess.py

示例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 
開發者ID:openstack,項目名稱:octavia,代碼行數:26,代碼來源:driver_agent.py

示例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 
開發者ID:reconnaissanceblindchess,項目名稱:reconchess,代碼行數:24,代碼來源:rc_connect.py

示例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) 
開發者ID:Percona-Lab,項目名稱:mongodb_consistent_backup,代碼行數:25,代碼來源:Task.py

示例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) 
開發者ID:HUJI-Deep,項目名稱:Generative-ConvACs,代碼行數:19,代碼來源:model_analyzer.py

示例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) 
開發者ID:apache,項目名稱:incubator-spot,代碼行數:15,代碼來源:collector.py

示例13: init

# 需要導入模塊: import signal [as 別名]
# 或者: from signal import SIG_IGN [as 別名]
def init():
    signal.signal(signal.SIGINT, signal.SIG_IGN) 
開發者ID:the-robot,項目名稱:sqliv,代碼行數:4,代碼來源:scanner.py

示例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') 
開發者ID:sippy,項目名稱:rtp_cluster,代碼行數:9,代碼來源:Signal.py

示例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 
開發者ID:tensorpack,項目名稱:dataflow,代碼行數:14,代碼來源:concurrency.py


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