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


Python multiprocessing.Condition類代碼示例

本文整理匯總了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
開發者ID:danwyryunq,項目名稱:TPSOUNQ,代碼行數:8,代碼來源:Cpu.py

示例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())
開發者ID:danwyryunq,項目名稱:TPSOUNQ,代碼行數:10,代碼來源:IODeviceManager.py

示例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
開發者ID:csabahruska,項目名稱:lambdacube.addon,代碼行數:7,代碼來源:TProcessPoolServer.py

示例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()
開發者ID:Jailander,項目名稱:mongodb_store,代碼行數:17,代碼來源:mongodb_log.py

示例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)
開發者ID:PaperclipBadger,項目名稱:hadamardequivalence,代碼行數:8,代碼來源:concurrencyutils.py

示例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
開發者ID:ihaque,項目名稱:grizzly,代碼行數:25,代碼來源:multiprocess.py

示例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()
開發者ID:SinaHonari,項目名稱:RCN,代碼行數:9,代碼來源:queue.py

示例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()
開發者ID:sq3,項目名稱:bundlewrap,代碼行數:11,代碼來源:ui.py

示例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()
開發者ID:0x24bin,項目名稱:exscript,代碼行數:11,代碼來源:DBPipeline.py

示例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
開發者ID:Milstein,項目名稱:pyretic,代碼行數:11,代碼來源:language.py

示例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()
開發者ID:SinaHonari,項目名稱:RCN,代碼行數:41,代碼來源:queue.py

示例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)
開發者ID:petermelias,項目名稱:hamlreloader,代碼行數:53,代碼來源:test_reloader.py

示例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()
開發者ID:0x24bin,項目名稱:exscript,代碼行數:14,代碼來源:Pipeline.py

示例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()
開發者ID:jojonki,項目名稱:ParlAI,代碼行數:16,代碼來源:worlds.py

示例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)
開發者ID:Lawouach,項目名稱:conductor,代碼行數:14,代碼來源:bus.py


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