当前位置: 首页>>代码示例>>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方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _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

示例2: __init__

# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import allocate_lock [as 别名]
def __init__(self, target, port=None):
        cmd.Cmd.__init__(self)
        if port is None:
            port = HEAPYPORT
        self.server_address = (LOCALHOST, port)
        self.target = target
        target.close = target.sys.modules['guppy.heapy.Remote'].IsolatedCaller(
        # target.close = IsolatedCaller(
            self.asynch_close)
        self.socket = None
        self.isclosed = 0
        self.closelock = _thread.allocate_lock()

        self.intlocals = {
        }
        self.do_reset('') 
开发者ID:zhuyifei1999,项目名称:guppy3,代码行数:18,代码来源:Remote.py

示例3: test_repr_stopped

# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import allocate_lock [as 别名]
def test_repr_stopped(self):
        # Verify that "stopped" shows up in repr(Thread) appropriately.
        started = _thread.allocate_lock()
        finish = _thread.allocate_lock()
        started.acquire()
        finish.acquire()
        def f():
            started.release()
            finish.acquire()
        t = threading.Thread(target=f)
        t.start()
        started.acquire()
        self.assertIn("started", repr(t))
        finish.release()
        # "stopped" should appear in the repr in a reasonable amount of time.
        # Implementation detail:  as of this writing, that's trivially true
        # if .join() is called, and almost trivially true if .is_alive() is
        # called.  The detail we're testing here is that "stopped" shows up
        # "all on its own".
        LOOKING_FOR = "stopped"
        for i in range(500):
            if LOOKING_FOR in repr(t):
                break
            time.sleep(0.01)
        self.assertIn(LOOKING_FOR, repr(t)) # we waited at least 5 seconds 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:27,代码来源:test_threading.py

示例4: test_with_traceback

# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import allocate_lock [as 别名]
def test_with_traceback(self):
        line_num=getlineno(lambda _: None)
        from _thread import allocate_lock
        def f():
            g()

        def g():
            h()

        def h():
            raise Exception('hello!!')

        try:
            with allocate_lock():
                f()
        except:
            self.assert_traceback([(line_num + 13, 30, FILE, 'test_with_traceback'),
                              (line_num + 3, 3, FILE, 'f'),
                              (line_num + 6, 3, FILE, 'g'),
                              (line_num + 9, 3, FILE, 'h')]) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:22,代码来源:test_traceback.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: __init__

# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import allocate_lock [as 别名]
def __init__(self) :
        self._processing   = False
        self._threadsCount = 0
        self._opLock       = allocate_lock()
        self._asyncSockets = { }
        self._readList     = [ ]
        self._writeList    = [ ]
        self._handlingList = [ ]

    # ------------------------------------------------------------------------ 
开发者ID:jczic,项目名称:MicroWebSrv2,代码行数:12,代码来源:XAsyncSockets.py

示例7: allocate_lock

# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import allocate_lock [as 别名]
def allocate_lock():
    """Dummy implementation of _thread.allocate_lock()."""
    return LockType() 
开发者ID:war-and-code,项目名称:jawfish,代码行数:5,代码来源:_dummy_thread.py

示例8: __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:war-and-code,项目名称:jawfish,代码行数:14,代码来源:_io.py

示例9: __init__

# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import allocate_lock [as 别名]
def __init__(self, socket, httpClient, httpResponse, maxRecvLen, threaded, acceptCallback) :
        self._socket            = socket
        self._httpCli           = httpClient
        self._closed            = True
        self._lock              = allocate_lock()
        self.RecvTextCallback   = None
        self.RecvBinaryCallback = None
        self.ClosedCallback     = None

        if hasattr(socket, 'read'):   # MicroPython
            self._socketfile = self._socket
        else:   # CPython
            self._socketfile = self._socket.makefile('rwb')

        if self._handshake(httpResponse) :
            self._ctrlBuf = MicroWebSocket._tryAllocByteArray(0x7D)
            self._msgBuf  = MicroWebSocket._tryAllocByteArray(maxRecvLen)
            if self._ctrlBuf and self._msgBuf :
                self._msgType = None
                self._msgLen  = 0
                if threaded :
                    if MicroWebSocket._tryStartThread(self._wsProcess, (acceptCallback, )) :
                        return
                else :
                    self._wsProcess(acceptCallback)
                    return
            print("MicroWebSocket : Out of memory on new WebSocket connection.")
        try :
            if self._socketfile is not self._socket:
                self._socketfile.close()
            self._socket.close()
        except :
            pass

    # ============================================================================
    # ===( Functions )============================================================
    # ============================================================================ 
开发者ID:jczic,项目名称:MicroWebSrv,代码行数:39,代码来源:microWebSocket.py

示例10: 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

示例11: 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

示例12: check_win_threads

# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import allocate_lock [as 别名]
def check_win_threads():
    import sys
    if sys.platform != 'win32':
        return

    import attach_script
    import time
    assert 'threading' not in sys.modules
    try:
        import thread
    except ImportError:
        import _thread as thread
    from ctypes import windll, WINFUNCTYPE, c_uint32, c_void_p, c_size_t

    ThreadProc = WINFUNCTYPE(c_uint32, c_void_p)

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

    @ThreadProc
    def method(_):
        lock2.acquire()
        with lock:
            pass  # Will only finish when lock is released.
        return 0

    with lock:
        windll.kernel32.CreateThread(None, c_size_t(0), method, None, c_uint32(0), None)
        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,代码行数:40,代码来源:_pydevd_test_find_main_thread_id.py

示例13: __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:caronc,项目名称:nzb-subliminal,代码行数:12,代码来源:rrule.py

示例14: __init__

# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import allocate_lock [as 别名]
def __init__(self, pool=None):
        self.pool = pool
        self.fd = 0
        self.pool_lock = _thread.allocate_lock()
        logger.critical('...') 
开发者ID:alcarithemad,项目名称:zfsp,代码行数:7,代码来源:zfuse.py

示例15: __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 OSError('"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:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:_pyio.py


注:本文中的_thread.allocate_lock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。