当前位置: 首页>>代码示例>>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;未经允许,请勿转载。