本文整理汇总了Python中_multiprocessing.SemLock类的典型用法代码示例。如果您正苦于以下问题:Python SemLock类的具体用法?Python SemLock怎么用?Python SemLock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SemLock类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_semaphore_contextmanager
def test_semaphore_contextmanager(self):
from _multiprocessing import SemLock
kind = self.SEMAPHORE
value = 1
maxvalue = 1
sem = SemLock(kind, value, maxvalue)
with sem:
assert sem._count() == 1
assert sem._count() == 0
示例2: test_semaphore_rebuild
def test_semaphore_rebuild(self):
from _multiprocessing import SemLock
kind = self.SEMAPHORE
value = 1
maxvalue = 1
sem = SemLock(kind, value, maxvalue)
sem2 = SemLock._rebuild(sem.handle, kind, value)
assert sem.handle == sem2.handle
示例3: __init__
def __init__(self, value=1, *, ctx):
SemLock.__init__(self, SEMAPHORE, value, value, ctx=ctx)
示例4: __init__
def __init__(self):
SemLock.__init__(self, SEMAPHORE, 1, 1)
示例5: __setstate__
def __setstate__(self, state):
self._semlock = _SemLock._rebuild(*state)
util.debug('recreated blocker with handle %r and name "%s"'
% (state[0], state[3]))
self._make_methods()
示例6: test_recursive
def test_recursive(self):
from _multiprocessing import SemLock
kind = self.RECURSIVE
value = 1
maxvalue = 1
sem = SemLock(kind, value, maxvalue)
sem.acquire()
sem.release()
assert sem._count() == 0
sem.acquire()
sem.release()
# now recursively
sem.acquire()
sem.acquire()
assert sem._count() == 2
sem.release()
sem.release()
示例7: test_semaphore
def test_semaphore(self):
from _multiprocessing import SemLock
import sys
assert SemLock.SEM_VALUE_MAX > 10
kind = self.SEMAPHORE
value = 1
maxvalue = 1
sem = SemLock(kind, value, maxvalue)
assert sem.kind == kind
assert sem.maxvalue == maxvalue
assert isinstance(sem.handle, (int, long))
assert sem._count() == 0
if sys.platform == 'darwin':
raises(NotImplementedError, 'sem._get_value()')
else:
assert sem._get_value() == 1
assert sem._is_zero() == False
sem.acquire()
assert sem._is_mine()
assert sem._count() == 1
if sys.platform == 'darwin':
raises(NotImplementedError, 'sem._get_value()')
else:
assert sem._get_value() == 0
assert sem._is_zero() == True
sem.release()
assert sem._count() == 0
sem.acquire()
sem._after_fork()
assert sem._count() == 0
示例8: __setstate__
def __setstate__(self, state):
reader, writer = state
self._reader = SemLock._rebuild(*reader)
self._writer = SemLock._rebuild(*writer)