本文整理汇总了Python中multiprocessing.Condition类的典型用法代码示例。如果您正苦于以下问题:Python Condition类的具体用法?Python Condition怎么用?Python Condition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Condition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
self.pcb = None
self.__mutex = RLock()
self.__pcb_not_set = Condition(self.__mutex)
self.__mem_not_allocated = Condition(self.__mutex)
self.__round_robin_policy_on = False
示例2: __init__
def __init__(self, a_device, a_kernel, std_in=StandardInput(), std_out=StandardOutput()):
Thread.__init__(self)
self.set_device(a_device)
self.set_kernel(a_kernel)
self.set_input(std_in)
self.set_output(std_out)
self.set_mutex(RLock())
self.set_queue(SoQueue())
self.device_is_in_use = Condition(self.get_mutex())
self.the_queue_is_empty = Condition(self.get_mutex())
示例3: __init__
def __init__(self, * args):
TServer.__init__(self, *args)
self.numWorkers = 10
self.workers = []
self.isRunning = Value('b', False)
self.stopCondition = Condition()
self.postForkCallback = None
示例4: Barrier
class Barrier(object):
def __init__(self, num_threads):
self.num_threads = num_threads
self.threads_left = Value('i', num_threads, lock=True)
self.mutex = Lock()
self.waitcond = Condition(self.mutex)
def wait(self):
self.mutex.acquire()
self.threads_left.value -= 1
if self.threads_left.value == 0:
self.threads_left.value = self.num_threads
self.waitcond.notify_all()
self.mutex.release()
else:
self.waitcond.wait()
self.mutex.release()
示例5: __init__
def __init__(self):
"""Initialises the RWLock."""
self._condition = Condition()
self._readers = Value(c_uint64, 0, lock=False)
self._writers_waiting = Value(c_uint64, 0, lock=False)
self.for_reading = self.ReadLock(self)
self.for_writing = self.WriteLock(self)
示例6: __call__
def __call__(self, cv_iterator, evaluator, fold_callback=None,
n_jobs=None):
"""
"""
condvar = Condition()
results = []
def _signal_cb(result):
condvar.acquire()
results.append(result)
condvar.notify()
condvar.release()
folds = list(cv_iterator)
pool, deferreds = self.async(folds, evaluator,
fold_callback=_signal_cb, n_jobs=n_jobs)
pool.close()
while len(results) < len(folds):
condvar.acquire()
condvar.wait()
fold_estimator, result = results[-1]
fold_callback(fold_estimator, result)
condvar.release()
pool.join()
return results
示例7: __init__
def __init__(self, maxsize):
self.queue = Queue(maxsize=maxsize)
self.lock = Lock()
self.getlock = Lock()
self.putcounter = Value('i', -1)
self.getcounter = Value('i', 0)
self.cond = Condition(self.lock)
self.manager = Manager()
self.getlist = self.manager.list()
示例8: activate_as_parent
def activate_as_parent(self, debug=False):
assert not self.child_mode
self.debug_mode = debug
self.jobs = []
self.output_lock = Lock()
self.parent_mode = True
self.output_queue = Queue()
self.status_line_cleared = Condition()
self.thread = Thread(target=self._print_thread)
self.thread.daemon = True
self.thread.start()
示例9: __init__
def __init__(self, engine, max_working = 1):
self.condition = Condition(RLock())
self.engine = engine
self.max_working = max_working
self.running = False
self.paused = False
self.metadata = sa.MetaData(self.engine)
self._table_prefix = 'exscript_pipeline_'
self._table_map = {}
self.__update_table_names()
self.clear()
示例10: __init__
def __init__(self):
super(CountBucket, self).__init__()
self.matches = set([])
self.runtime_stats_query_fun = None
self.outstanding_switches = []
self.packet_count = 0
self.byte_count = 0
self.packet_count_persistent = 0
self.byte_count_persistent = 0
self.in_update_cv = Condition()
self.in_update = False
示例11: OrderedQueue
class OrderedQueue(object):
def __init__(self, maxsize):
self.queue = Queue(maxsize=maxsize)
self.lock = Lock()
self.getlock = Lock()
self.putcounter = Value('i', -1)
self.getcounter = Value('i', 0)
self.cond = Condition(self.lock)
self.manager = Manager()
self.getlist = self.manager.list()
def put(self, index, elem):
with self.lock:
while index != self.putcounter.value + 1:
self.cond.wait()
self.queue.put((index, elem))
#sys.stderr.write("right after adding data with SEED %i. Queue size is now %i\n" %(index, self.queue.qsize()))
self.putcounter.value += 1
self.cond.notify_all()
def get(self):
with self.getlock:
for i, element in enumerate(self.getlist):
index, elem = element
if index == self.getcounter.value:
self.getcounter.value += 1
del self.getlist[i]
return (index, elem)
while True:
index, elem = self.queue.get()
if index == self.getcounter.value:
self.getcounter.value += 1
return (index, elem)
else:
self.getlist.append((index, elem))
def close(self):
return self.queue.close()
def qsize(self):
return self.queue.qsize()
示例12: test_watch_directory
def test_watch_directory():
def _cleanup(path):
for f in listdir(path):
p = join(path, f)
if isdir(p):
rmtree(p)
elif f != '.nothing':
unlink(p)
sample_template = ''
sample_directory = dirname(realpath(__file__)) + '/sample/'
watch_directory = sample_directory + 'watch/'
render_directory = sample_directory + 'render/'
template_directory = sample_directory + 'templates/'
with open(template_directory + 'haml.tmpl', 'r') as f:
sample_template = f.read()
condition = Condition()
p = Process(target=reloader.watch_directory,
args=(watch_directory, render_directory, condition))
condition.acquire()
p.start()
condition.wait()
try:
with open(watch_directory + 'test.haml', 'w') as f:
f.write(sample_template)
subdir = watch_directory + 'test_subdir/'
try:
mkdir(subdir)
except OSError:
if not isdir(subdir):
raise
with open(subdir + 'test_two.haml', 'w') as f:
f.write(sample_template)
sleep(1)
assert_true(exists(render_directory + 'test.html'))
assert_true(exists(render_directory + 'test_subdir/test_two.html'))
except:
raise
finally:
condition.release()
p.terminate()
p.join()
sleep(1)
_cleanup(watch_directory)
_cleanup(render_directory)
示例13: __init__
def __init__(self, max_working = 1):
self.condition = Condition(RLock())
self.max_working = max_working
self.running = True
self.paused = False
self.queue = None
self.force = None
self.sleeping = None
self.working = None
self.item2id = None
self.id2item = None # for performance reasons
self.name2id = None
self.id2name = None
self.clear()
示例14: __init__
def __init__(self, world_class, opt, agents):
self.inner_world = world_class(opt, agents)
self.queued_items = Semaphore(0) # counts num exs to be processed
self.epochDone = Condition() # notifies when exs are finished
self.terminate = Value('b', False) # tells threads when to shut down
self.cnt = Value('i', 0) # number of exs that remain to be processed
self.threads = []
for i in range(opt['numthreads']):
self.threads.append(HogwildProcess(i, world_class, opt,
agents, self.queued_items,
self.epochDone, self.terminate,
self.cnt))
for t in self.threads:
t.start()
示例15: SynchronizingBus
class SynchronizingBus(Bus):
def __init__(self, sync_delay=1):
Bus.__init__(self)
self.sync_delay = sync_delay
self.condition = Condition()
def start(self):
import time
time.sleep(self.sync_delay)
self.log("Releasing children")
self.condition.acquire()
self.condition.notify_all()
self.condition.release()
Bus.start(self)