当前位置: 首页>>代码示例>>Python>>正文


Python queue.Queue方法代码示例

本文整理汇总了Python中six.moves.queue.Queue方法的典型用法代码示例。如果您正苦于以下问题:Python queue.Queue方法的具体用法?Python queue.Queue怎么用?Python queue.Queue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves.queue的用法示例。


在下文中一共展示了queue.Queue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: reset_state

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Queue [as 别名]
def reset_state(self):
        super(MultiThreadMapData, self).reset_state()
        if self._threads:
            self._threads[0].stop()
            for t in self._threads:
                t.join()

        self._in_queue = queue.Queue()
        self._out_queue = queue.Queue()
        self._evt = threading.Event()
        self._threads = [MultiThreadMapData._Worker(
            self._in_queue, self._out_queue, self._evt, self.map_func)
            for _ in range(self.num_thread)]
        for t in self._threads:
            t.start()

        self._guard = DataFlowReentrantGuard()

        # Call once at the beginning, to ensure inq+outq has a total of buffer_size elements
        self._fill_buffer() 
开发者ID:tensorpack,项目名称:dataflow,代码行数:22,代码来源:parallel_map.py

示例2: __init__

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Queue [as 别名]
def __init__(self, get_df, num_prefetch, num_thread):
        """
        Args:
            get_df ( -> DataFlow): a callable which returns a DataFlow.
                Each thread will call this function to get the DataFlow to use.
                Therefore do not return the same DataFlow object for each call,
                unless your dataflow is stateless.
            num_prefetch (int): size of the queue
            num_thread (int): number of threads
        """
        assert num_thread > 0, num_thread
        assert num_prefetch > 0, num_prefetch
        self.num_thread = num_thread
        self.queue = queue.Queue(maxsize=num_prefetch)
        self.threads = [
            MultiThreadRunner._Worker(get_df, self.queue)
            for _ in range(num_thread)]

        try:
            self._size = self.__len__()
        except NotImplementedError:
            self._size = -1 
开发者ID:tensorpack,项目名称:dataflow,代码行数:24,代码来源:parallel.py

示例3: setUpClass

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Queue [as 别名]
def setUpClass(self):
        self.projectdb = ProjectDB([os.path.join(os.path.dirname(__file__), 'data_fetcher_processor_handler.py')])
        self.fetcher = Fetcher(None, None, async_mode=False)
        self.status_queue = Queue()
        self.newtask_queue = Queue()
        self.result_queue = Queue()
        self.httpbin_thread = utils.run_in_subprocess(httpbin.app.run, port=14887, passthrough_errors=False)
        self.httpbin = 'http://127.0.0.1:14887'
        self.proxy_thread = subprocess.Popen(['pyproxy', '--username=binux',
                                              '--password=123456', '--port=14830',
                                              '--debug'], close_fds=True)
        self.proxy = '127.0.0.1:14830'
        self.processor = Processor(projectdb=self.projectdb,
                                   inqueue=None,
                                   status_queue=self.status_queue,
                                   newtask_queue=self.newtask_queue,
                                   result_queue=self.result_queue)
        self.project_name = 'data_fetcher_processor_handler'
        time.sleep(0.5) 
开发者ID:binux,项目名称:pyspider,代码行数:21,代码来源:test_fetcher_processor.py

示例4: get

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Queue [as 别名]
def get(self):
        '''Get a task from queue when bucket available'''
        if self.bucket.get() < 1:
            return None
        now = time.time()
        self.mutex.acquire()
        try:
            task = self.priority_queue.get_nowait()
            self.bucket.desc()
        except Queue.Empty:
            self.mutex.release()
            return None
        task.exetime = now + self.processing_timeout
        self.processing.put(task)
        self.mutex.release()
        return task.taskid 
开发者ID:binux,项目名称:pyspider,代码行数:18,代码来源:task_queue.py

示例5: _check_task_done

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Queue [as 别名]
def _check_task_done(self):
        '''Check status queue'''
        cnt = 0
        try:
            while True:
                task = self.status_queue.get_nowait()
                # check _on_get_info result here
                if task.get('taskid') == '_on_get_info' and 'project' in task and 'track' in task:
                    if task['project'] not in self.projects:
                        continue
                    project = self.projects[task['project']]
                    project.on_get_info(task['track'].get('save') or {})
                    logger.info(
                        '%s on_get_info %r', task['project'], task['track'].get('save', {})
                    )
                    continue
                elif not self.task_verify(task):
                    continue
                self.on_task_status(task)
                cnt += 1
        except Queue.Empty:
            pass
        return cnt 
开发者ID:binux,项目名称:pyspider,代码行数:25,代码来源:scheduler.py

示例6: setup

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Queue [as 别名]
def setup(self, config):
    """
    Establish connection to Elasticsearch cluster and start periodic commit.

    :param config: Configuration object.
    :type config: ``dict``
    """
    self.config = config
    self.context_size = config.get(helper.CONTEXT_SIZE, 120)
    self.elastic_bulk = queue.Queue()
    self.elastic = self.config[helper.INJECTOR].get_elasticsearch()
    self.helper = self.config[helper.INJECTOR].get_elasticsearch_helper()
    self.create_mapping()

    thread = threading.Thread(target=self._commit, args=())
    thread.daemon = True
    thread.start()
    self.thread = thread 
开发者ID:pcbje,项目名称:gransk,代码行数:20,代码来源:es_index.py

示例7: __init__

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Queue [as 别名]
def __init__(self, agent, in_queue_size):
        """
        Initializes the worker with a RLGraph agent and queues for

        Args:
            agent (Agent): RLGraph agent used to execute local updates.
            input_queue (queue.Queue): Input queue the worker will use to poll samples.
            output_queue (queue.Queue): Output queue the worker will use to push results of local
                update computations.
        """
        super(UpdateWorker, self).__init__()

        # Agent to use for updating.
        self.agent = agent
        self.input_queue = queue.Queue(maxsize=in_queue_size)
        self.output_queue = queue.Queue()

        # Terminate when host process terminates.
        self.daemon = True

        # Flag for main thread.
        self.update_done = False 
开发者ID:rlgraph,项目名称:rlgraph,代码行数:24,代码来源:apex_executor.py

示例8: test_response_on_queue

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Queue [as 别名]
def test_response_on_queue(self):
        g = MockGrader()
        pl = self._make_payload({
            'student_response': 'blah',
            'grader_payload': json.dumps({
                'grader': 'correct'
                })
            })
        q = Queue()
        reply = g.process_item(pl, queue=q)
        popped = q.get()
        self.assertEqual(reply, popped)

        del pl['xqueue_body']
        try:
            g.process_item(pl, queue=q)
        except Exception as e:
            popped = q.get()
            self.assertEqual(e, popped) 
开发者ID:edx,项目名称:xqueue-watcher,代码行数:21,代码来源:test_grader.py

示例9: __init__

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Queue [as 别名]
def __init__(self, rate=RATE, chunk=CHUNK, server_name='127.0.0.1',
                 port=4444):
        self._rate = rate
        self._chunk = chunk
        self._server_name = server_name
        self._port = port

        # Socket for connection
        self.s = None
        self._connected = False

        # Audio data thread to get data from server
        self.data_thread = threading.Thread(target=self._get_server_data)
        self.data_thread.daemon = True

        # Create a thread-safe buffer of audio data
        self._buff = queue.Queue()
        self.closed = True 
开发者ID:piraka9011,项目名称:dialogflow_ros,代码行数:20,代码来源:AudioServerStream.py

示例10: setup_client_backend

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Queue [as 别名]
def setup_client_backend(self):
        """
        Setup backend client thread as daemon

        Returns:
            None

        """
        self.backend_queue = queue.Queue()
        self.backend_stop_event = threading.Event()
        self.setup_client()
        t = threading.Thread(target=self._backend_worker, name="airtouch")
        # t.daemon = True
        t.start()
        self.backend_thread = t
        self.handle = self.backend_queue.put 
开发者ID:AirtestProject,项目名称:Airtest,代码行数:18,代码来源:base_touch.py

示例11: __init__

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Queue [as 别名]
def __init__(self, predictors, batch_size=5, debug_charts=False, worker_id=None, neptune_client=None):
        """ :param predictors: a list of OnlinePredictor"""
        assert len(predictors)
        for k in predictors:
            #assert isinstance(k, OnlinePredictor), type(k)
            # TODO use predictors.return_input here
            assert k.return_input == False
            #queue_size=len(predictors)*100
            queue_size=len(predictors)*1
        self.input_queue = queue.Queue(maxsize=queue_size)
        self.threads = [
            PredictorWorkerThread(
                self.input_queue, f, id, batch_size=batch_size,
                debug_charts=debug_charts,
                worker_id=worker_id,
                neptune_client=neptune_client)
            for id, f in enumerate(predictors)]

        if six.PY2:
            # TODO XXX set logging here to avoid affecting TF logging
            import tornado.options as options
            options.parse_command_line(['--logging=debug']) 
开发者ID:anonymous-author1,项目名称:DDRL,代码行数:24,代码来源:concurrency.py

示例12: __init__

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Queue [as 别名]
def __init__(self, worker_id, neptune_client, pipe_c2s, pipe_s2c, model, dummy, predictor_threads, predict_batch_size=16, do_train=True):
        # predictor_threads is previous PREDICTOR_THREAD
        super(MySimulatorMaster, self).__init__(pipe_c2s, pipe_s2c, args.simulator_procs, os.getpid())
        self.M = model
        self.do_train = do_train

        # the second queue is here!
        self.queue = queue.Queue(maxsize=args.my_sim_master_queue)
        self.dummy = dummy
        self.predictor_threads = predictor_threads

        self.last_queue_put = start_timer()
        self.queue_put_times = []
        self.predict_batch_size = predict_batch_size
        self.counter = 0

        self.worker_id = worker_id
        self.neptune_client = neptune_client
        self.stats = defaultdict(StatCounter)
        self.games = StatCounter() 
开发者ID:anonymous-author1,项目名称:DDRL,代码行数:22,代码来源:train.py

示例13: run

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Queue [as 别名]
def run(self):
        if not self.containers:
            return

        queue = Queue()
        thread_args = queue, self.log_args
        thread_map = build_thread_map(self.containers, self.presenters, thread_args)

        for line in consume_queue(queue, self.cascade_stop):
            remove_stopped_threads(thread_map)

            if not line:
                if not thread_map:
                    # There are no running containers left to tail, so exit
                    return
                # We got an empty line because of a timeout, but there are still
                # active containers to tail, so continue
                continue

            try:
                self.output.write(line)
                self.output.flush()
            except ValueError:
                # ValueError: I/O operation on closed file
                break 
开发者ID:openai,项目名称:universe,代码行数:27,代码来源:log_printer.py

示例14: __init__

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Queue [as 别名]
def __init__(self, num_threads):
        assert num_threads >= 1
        self.task_queue = Queue.Queue()
        self.result_queues = dict()
        self.num_threads = num_threads
        for idx in range(self.num_threads):
            thread = WorkerThread(self.task_queue)
            thread.daemon = True
            thread.start() 
开发者ID:zalandoresearch,项目名称:disentangling_conditional_gans,代码行数:11,代码来源:dataset_tool.py

示例15: add_task

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Queue [as 别名]
def add_task(self, func, args=()):
        assert hasattr(func, '__call__') # must be a function
        if func not in self.result_queues:
            self.result_queues[func] = Queue.Queue()
        self.task_queue.put((func, args, self.result_queues[func])) 
开发者ID:zalandoresearch,项目名称:disentangling_conditional_gans,代码行数:7,代码来源:dataset_tool.py


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