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


Python thread.allocate_lock方法代碼示例

本文整理匯總了Python中thread.allocate_lock方法的典型用法代碼示例。如果您正苦於以下問題:Python thread.allocate_lock方法的具體用法?Python thread.allocate_lock怎麽用?Python thread.allocate_lock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在thread的用法示例。


在下文中一共展示了thread.allocate_lock方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import allocate_lock [as 別名]
def __init__(self):
        self.debugApplication = None
        self.debuggingThread = None
        self.debuggingThreadStateHandle = None
        self.stackSnifferCookie = self.stackSniffer = None
        self.codeContainerProvider = None
        self.debuggingThread = None
        self.breakFlags = None
        self.breakReason = None
        self.appDebugger = None
        self.appEventConnection = None
        self.logicalbotframe = None # Anything at this level or below does not exist!
        self.currentframe = None # The frame we are currently in.
        self.recursiveData = [] # Data saved for each reentery on this thread.
        bdb.Bdb.__init__(self)
        self._threadprotectlock = thread.allocate_lock()
        self.reset() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:adb.py

示例2: test_with_traceback

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import allocate_lock [as 別名]
def test_with_traceback():
    from thread import allocate_lock
    def f():
        g()
    
    def g():
        h()
    
    def h():
        raise Exception('hello!!')
        
    try:
        with allocate_lock():
            f()
    except:
        assert_traceback([(Line397+14, 30, 'test_traceback.py', 'test_with_traceback'), 
                          (Line397+4, 3, 'test_traceback.py', 'f'), 
                          (Line397+7, 3, 'test_traceback.py', 'g'),
                          (Line397+10, 3, 'test_traceback.py', 'h')]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_traceback.py

示例3: __init__

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import allocate_lock [as 別名]
def __init__(self, port="/dev/ttyUSB0", baudrate=57600, timeout=0.5):
        
        self.PID_RATE = 30 # Do not change this!  It is a fixed property of the Arduino PID controller.
        self.PID_INTERVAL = 1000 / 30
        
        self.port = port
        self.baudrate = baudrate
        self.timeout = timeout
        self.encoder_count = 0
        self.writeTimeout = timeout
        self.interCharTimeout = timeout / 30.
    
        # Keep things thread safe
        self.mutex = thread.allocate_lock()
            
        # An array to cache analog sensor readings
        self.analog_sensor_cache = [None] * self.N_ANALOG_PORTS
        
        # An array to cache digital sensor readings
        self.digital_sensor_cache = [None] * self.N_DIGITAL_PORTS 
開發者ID:EAIBOT,項目名稱:dashgo,代碼行數:22,代碼來源:dashgo_driver.py

示例4: _run_in_multiple_threads

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import allocate_lock [as 別名]
def _run_in_multiple_threads(test1):
    test1()
    import sys
    try:
        import thread
    except ImportError:
        import _thread as thread
    errors = []
    def wrapper(lock):
        try:
            test1()
        except:
            errors.append(sys.exc_info())
        lock.release()
    locks = []
    for i in range(10):
        _lock = thread.allocate_lock()
        _lock.acquire()
        thread.start_new_thread(wrapper, (_lock,))
        locks.append(_lock)
    for _lock in locks:
        _lock.acquire()
        if errors:
            raise errors[0][1] 
開發者ID:johncsnyder,項目名稱:SwiftKitten,代碼行數:26,代碼來源:test_verify.py

示例5: __init__

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import allocate_lock [as 別名]
def __init__(self, maxEntries=10000, maxAge=14400):
        """Create a new SessionCache.

        @type maxEntries: int
        @param maxEntries: The maximum size of the cache.  When this
        limit is reached, the oldest sessions will be deleted as
        necessary to make room for new ones.  The default is 10000.

        @type maxAge: int
        @param maxAge:  The number of seconds before a session expires
        from the cache.  The default is 14400 (i.e. 4 hours)."""

        self.lock = thread.allocate_lock()

        # Maps sessionIDs to sessions
        self.entriesDict = {}

        #Circular list of (sessionID, timestamp) pairs
        self.entriesList = [(None,None)] * maxEntries

        self.firstIndex = 0
        self.lastIndex = 0
        self.maxAge = maxAge 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:25,代碼來源:SessionCache.py

示例6: allocate_lock

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import allocate_lock [as 別名]
def allocate_lock():
    """Dummy implementation of thread.allocate_lock()."""
    return LockType() 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:5,代碼來源:dummy_thread.py

示例7: __init__

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import allocate_lock [as 別名]
def __init__(self, raw, buffer_size=DEFAULT_BUFFER_SIZE):
        """Create a new buffered reader using the given readable raw IO object.
        """
        if not raw.readable():
            raise IOError('"raw" argument must be readable.')

        _BufferedIOMixin.__init__(self, raw)
        if buffer_size <= 0:
            raise ValueError("invalid buffer size")
        self.buffer_size = buffer_size
        self._reset_read_buf()
        self._read_lock = Lock() 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:14,代碼來源:_pyio.py

示例8: InitializeErrorWatcher

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import allocate_lock [as 別名]
def InitializeErrorWatcher(self):
        from System.Threading import Thread, ThreadStart
        import thread            
        self.errorLock = thread.allocate_lock()
        self.errorString = ""
        th = Thread(ThreadStart(self.WatchErrorStream))
        th.IsBackground = True
        th.Start() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:console_util.py

示例9: test_thread_lock

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import allocate_lock [as 別名]
def test_thread_lock(self):
        import thread

        temp_lock = thread.allocate_lock()
        self.assertTrue(hasattr(temp_lock, "__enter__"))
        self.assertTrue(hasattr(temp_lock, "__exit__"))
        self.assertTrue(not temp_lock.locked())
        with temp_lock:
            self.assertTrue(temp_lock.locked())
        self.assertTrue(not temp_lock.locked())
        
        with thread.allocate_lock(): pass 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:test_python25.py

示例10: test_finalize_runnning_thread

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import allocate_lock [as 別名]
def test_finalize_runnning_thread(self):
        # Issue 1402: the PyGILState_Ensure / _Release functions may be called
        # very late on python exit: on deallocation of a running thread for
        # example.
        try:
            import ctypes
        except ImportError:
            if verbose:
                print("test_finalize_with_runnning_thread can't import ctypes")
            return  # can't do anything

        rc = subprocess.call([sys.executable, "-c", """if 1:
            import ctypes, sys, time, thread

            # This lock is used as a simple event variable.
            ready = thread.allocate_lock()
            ready.acquire()

            # Module globals are cleared before __del__ is run
            # So we save the functions in class dict
            class C:
                ensure = ctypes.pythonapi.PyGILState_Ensure
                release = ctypes.pythonapi.PyGILState_Release
                def __del__(self):
                    state = self.ensure()
                    self.release(state)

            def waitingThread():
                x = C()
                ready.release()
                time.sleep(100)

            thread.start_new_thread(waitingThread, ())
            ready.acquire()  # Be sure the other thread is waiting.
            sys.exit(42)
            """])
        self.assertEqual(rc, 42) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:39,代碼來源:test_threading.py

示例11: __init__

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import allocate_lock [as 別名]
def __init__(self, cache=False):
        if cache:
            self._cache = []
            self._cache_lock = thread.allocate_lock()
            self._cache_gen  = self._iter()
            self._cache_complete = False
        else:
            self._cache = None
            self._cache_complete = False
        self._len = None 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:12,代碼來源:rrule.py

示例12: test_finalize_runnning_thread

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import allocate_lock [as 別名]
def test_finalize_runnning_thread(self):
        # Issue 1402: the PyGILState_Ensure / _Release functions may be called
        # very late on python exit: on deallocation of a running thread for
        # example.
        try:
            import ctypes
        except ImportError:
            self.skipTest('requires ctypes')

        rc = subprocess.call([sys.executable, "-c", """if 1:
            import ctypes, sys, time, thread

            # This lock is used as a simple event variable.
            ready = thread.allocate_lock()
            ready.acquire()

            # Module globals are cleared before __del__ is run
            # So we save the functions in class dict
            class C:
                ensure = ctypes.pythonapi.PyGILState_Ensure
                release = ctypes.pythonapi.PyGILState_Release
                def __del__(self):
                    state = self.ensure()
                    self.release(state)

            def waitingThread():
                x = C()
                ready.release()
                time.sleep(100)

            thread.start_new_thread(waitingThread, ())
            ready.acquire()  # Be sure the other thread is waiting.
            sys.exit(42)
            """])
        self.assertEqual(rc, 42) 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:37,代碼來源:test_threading.py

示例13: check_main_thread_id_multiple_threads

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import allocate_lock [as 別名]
def check_main_thread_id_multiple_threads():
    import attach_script
    import sys
    import time
    assert 'threading' not in sys.modules
    try:
        import thread
    except ImportError:
        import _thread as thread

    lock = thread.allocate_lock()
    lock2 = thread.allocate_lock()

    def method():
        lock2.acquire()
        with lock:
            pass  # Will only finish when lock is released.

    with lock:
        thread.start_new_thread(method, ())
        while not lock2.locked():
            time.sleep(.1)

        wait_for_condition(lambda: len(sys._current_frames()) == 2)

        main_thread_id, log_msg = attach_script.get_main_thread_id(None)
        assert main_thread_id == thread.get_ident(), 'Found: %s, Expected: %s' % (main_thread_id, thread.get_ident())
        assert not log_msg
        assert 'threading' not in sys.modules
    wait_for_condition(lambda: len(sys._current_frames()) == 1) 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:32,代碼來源:_pydevd_test_find_main_thread_id.py

示例14: check_fix_main_thread_id_multiple_threads

# 需要導入模塊: import thread [as 別名]
# 或者: from thread import allocate_lock [as 別名]
def check_fix_main_thread_id_multiple_threads():
    import attach_script
    import sys
    import time
    assert 'threading' not in sys.modules
    try:
        import thread
    except ImportError:
        import _thread as thread

    lock = thread.allocate_lock()
    lock2 = thread.allocate_lock()

    def method():
        lock2.acquire()
        import threading  # Note: imported on wrong thread
        assert threading.current_thread().ident == thread.get_ident()
        assert threading.current_thread() is attach_script.get_main_thread_instance(threading)

        attach_script.fix_main_thread_id()

        assert threading.current_thread().ident == thread.get_ident()
        assert threading.current_thread() is not attach_script.get_main_thread_instance(threading)

        with lock:
            pass  # Will only finish when lock is released.

    with lock:
        thread.start_new_thread(method, ())
        while not lock2.locked():
            time.sleep(.1)

        wait_for_condition(lambda: len(sys._current_frames()) == 2)

        main_thread_id, log_msg = attach_script.get_main_thread_id(None)
        assert main_thread_id == thread.get_ident(), 'Found: %s, Expected: %s' % (main_thread_id, thread.get_ident())
        assert not log_msg
        assert 'threading' in sys.modules
        import threading
        assert threading.current_thread().ident == main_thread_id
    wait_for_condition(lambda: len(sys._current_frames()) == 1) 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:43,代碼來源:_pydevd_test_find_main_thread_id.py


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