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


Python queues.Queue方法代码示例

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


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

示例1: __init__

# 需要导入模块: from asyncio import queues [as 别名]
# 或者: from asyncio.queues import Queue [as 别名]
def __init__(self, in_state, in_forward, search_threads):
        self.noise_eps = 0.25
        self.dirichlet_alpha = 0.3    #0.03
        self.p_ = (1 - self.noise_eps) * 1 + self.noise_eps * np.random.dirichlet([self.dirichlet_alpha])
        self.root = leaf_node(None, self.p_, in_state)
        self.c_puct = 5    #1.5
        # self.policy_network = in_policy_network
        self.forward = in_forward
        self.node_lock = defaultdict(Lock)

        self.virtual_loss = 3
        self.now_expanding = set()
        self.expanded = set()
        self.cut_off_depth = 30
        # self.QueueItem = namedtuple("QueueItem", "feature future")
        self.sem = asyncio.Semaphore(search_threads)
        self.queue = Queue(search_threads)
        self.loop = asyncio.get_event_loop()
        self.running_simulation_num = 0 
开发者ID:chengstone,项目名称:cchess-zero,代码行数:21,代码来源:main.py

示例2: __init__

# 需要导入模块: from asyncio import queues [as 别名]
# 或者: from asyncio.queues import Queue [as 别名]
def __init__(self, config: Config, model, play_config=None):

        self.config = config
        self.model = model
        self.play_config = play_config or self.config.play
        self.api = Connect4ModelAPI(self.config, self.model)

        self.labels_n = config.n_labels
        self.var_n = defaultdict(lambda: np.zeros((self.labels_n,)))
        self.var_w = defaultdict(lambda: np.zeros((self.labels_n,)))
        self.var_q = defaultdict(lambda: np.zeros((self.labels_n,)))
        self.var_u = defaultdict(lambda: np.zeros((self.labels_n,)))
        self.var_p = defaultdict(lambda: np.zeros((self.labels_n,)))
        self.expanded = set()
        self.now_expanding = set()
        self.prediction_queue = Queue(self.play_config.prediction_queue_size)
        self.sem = asyncio.Semaphore(self.play_config.parallel_search_num)

        self.moves = []
        self.loop = asyncio.get_event_loop()
        self.running_simulation_num = 0

        self.thinking_history = {}  # for fun 
开发者ID:Zeta36,项目名称:connect4-alpha-zero,代码行数:25,代码来源:player_connect4.py

示例3: submit

# 需要导入模块: from asyncio import queues [as 别名]
# 或者: from asyncio.queues import Queue [as 别名]
def submit(self, flow, flow_id=0, **kwargs):
        """
        execute a set of tasks with DAG-topology into consideration
        :param task_names: the tasks to form DAG
        :return:
        """

        assert isinstance(flow, Flow)
        self.executing_flow = flow
        self.executing_flow_id = flow_id
        self.kwargs = kwargs

        for task_name in self.executing_flow.tasks:
            self.context.get_task(task_name).pending(self.context, flow_id, flow.name)
        io_loop = asyncio.new_event_loop()
        asyncio.set_event_loop(io_loop)
        self.wait_queue = queues.Queue()
        self.exec_queue = queues.Queue()
        ret = io_loop.run_until_complete(self.execute_dag_ioloop())
        io_loop.close()
        return ret 
开发者ID:bailaohe,项目名称:parade,代码行数:23,代码来源:single.py

示例4: listify_queue

# 需要导入模块: from asyncio import queues [as 别名]
# 或者: from asyncio.queues import Queue [as 别名]
def listify_queue(queue):
        """
        Due to the asyncronous nature of the queue
        this is for making a standard list out of a queue item.
        :param queue: An asyncronous queue storage.
        :type queue: asyncio.Queue
        :return:
        :rtype: list[sigma.core.mechanics.music.Queue
        """
        item_list = []
        while not queue.empty():
            item = await queue.get()
            item_list.append(item)
        for item in item_list:
            await queue.put(item)
        return item_list 
开发者ID:lu-ci,项目名称:apex-sigma-core,代码行数:18,代码来源:music.py

示例5: __init__

# 需要导入模块: from asyncio import queues [as 别名]
# 或者: from asyncio.queues import Queue [as 别名]
def __init__(self, cloud):
        """Initialize Google Report State."""
        super().__init__(cloud)
        self._connect_lock = asyncio.Lock()
        self._to_send = Queue(100)
        self._message_sender_task = None
        # Local code waiting for a response
        self._response_handler: Dict[str, asyncio.Future] = {}
        self.register_on_connect(self._async_on_connect)
        self.register_on_disconnect(self._async_on_disconnect)

        # Register start/stop
        cloud.register_on_stop(self.disconnect) 
开发者ID:NabuCasa,项目名称:hass-nabucasa,代码行数:15,代码来源:google_report_state.py

示例6: verify_producer

# 需要导入模块: from asyncio import queues [as 别名]
# 或者: from asyncio.queues import Queue [as 别名]
def verify_producer(
    master: Master,
    config: ConfigParser,
    all_package_files: List[Path],
    mirror_base_path: Path,
    json_files: List[str],
    args: argparse.Namespace,
    executor: Optional[concurrent.futures.ThreadPoolExecutor] = None,
) -> None:
    queue: asyncio.Queue = asyncio.Queue()
    for jf in json_files:
        await queue.put(jf)

    async def consume(q: Queue) -> None:
        while not q.empty():
            json_file = await q.get()
            await verify(
                master,
                config,
                json_file,
                mirror_base_path,
                all_package_files,
                args,
                executor,
            )

    await asyncio.gather(
        *[consume(queue)] * config.getint("mirror", "verifiers", fallback=3)
    ) 
开发者ID:pypa,项目名称:bandersnatch,代码行数:31,代码来源:verify.py

示例7: get_queue

# 需要导入模块: from asyncio import queues [as 别名]
# 或者: from asyncio.queues import Queue [as 别名]
def get_queue(self, guild_id: int):
        """
        Gets a guild's queue.
        If the guild doesn't have one, it'll be generated.
        :param guild_id: The Guild ID.
        :type guild_id: int
        :return:
        :rtype: asyncio.Queue
        """
        queue = self.queues.get(guild_id, Queue())
        self.queues.update({guild_id: queue})
        return queue 
开发者ID:lu-ci,项目名称:apex-sigma-core,代码行数:14,代码来源:music.py

示例8: __init__

# 需要导入模块: from asyncio import queues [as 别名]
# 或者: from asyncio.queues import Queue [as 别名]
def __init__(self, limit: int = 50):
        self._loop = asyncio.get_event_loop()
        self._limit = limit
        self.logger = logging.getLogger(self.__class__.__name__)
        self._pending_queue: Queue = Queue()
        self._done_queue: Queue = Queue()
        self._running_count = 0
        self._closed = False 
开发者ID:strongbugman,项目名称:ant_nest,代码行数:10,代码来源:pool.py

示例9: as_completed

# 需要导入模块: from asyncio import queues [as 别名]
# 或者: from asyncio.queues import Queue [as 别名]
def as_completed(
        self, coros: typing.Iterable[typing.Awaitable], limit: int = 50,
    ) -> typing.Generator[typing.Awaitable, None, None]:
        """Like "asyncio.as_completed",
        run and iter coros out of pool.

        :param limit: set to "settings.JOB_LIMIT" by default,
        this "limit" is not shared with pool`s limit
        """
        coros = iter(coros)
        queue: Queue = Queue()
        todo: typing.List[asyncio.Future] = []

        def _done_callback(f):
            queue.put_nowait(f)
            todo.remove(f)
            try:
                nf = asyncio.ensure_future(next(coros))
                nf.add_done_callback(_done_callback)
                todo.append(nf)
            except StopIteration:
                pass

        async def _wait_for_one():
            return (await queue.get()).result()

        if limit <= 0:
            fs = {asyncio.ensure_future(cor, loop=self._loop) for cor in coros}
        else:
            fs = {
                asyncio.ensure_future(cor, loop=self._loop)
                for cor in islice(coros, 0, limit)
            }
        for f in fs:
            f.add_done_callback(_done_callback)
            todo.append(f)

        while len(todo) > 0 or queue.qsize() > 0:
            yield _wait_for_one() 
开发者ID:strongbugman,项目名称:ant_nest,代码行数:41,代码来源:pool.py

示例10: start

# 需要导入模块: from asyncio import queues [as 别名]
# 或者: from asyncio.queues import Queue [as 别名]
def start(self):
        """ 入口方法 """
        # queue必须创建在run()方法内 https://stackoverflow.com/questions/53724665/using-queues-results-in-asyncio-exception-got-future-future-pending-attached
        self.targets_q = Queue()  # url, name
        await self.targets_q.put((self.url, "index"))
        self.running = True

        tasks = []
        for i in range(self.task_count):
            tasks.append(asyncio.create_task(self.dump()))
        for t in tasks:
            await t 
开发者ID:0xHJK,项目名称:dumpall,代码行数:14,代码来源:idxdumper.py

示例11: __init__

# 需要导入模块: from asyncio import queues [as 别名]
# 或者: from asyncio.queues import Queue [as 别名]
def __init__(self, url: str, outdir: str):
        super(Dumper, self).__init__(url, outdir)
        self.base_url = re.sub("/\.DS_Store.*", "", url)
        self.url_queue = Queue() 
开发者ID:0xHJK,项目名称:dumpall,代码行数:6,代码来源:dsdumper.py

示例12: __init__

# 需要导入模块: from asyncio import queues [as 别名]
# 或者: from asyncio.queues import Queue [as 别名]
def __init__(self, config: Config, model, play_config=None, enable_resign=True, mtcs_info=None, api=None):
        """

        :param config:
        :param reversi_zero.agent.model.ReversiModel|None model:
        :param MCTSInfo mtcs_info:
        :parameter ReversiModelAPI api:
        """
        self.config = config
        self.model = model
        self.play_config = play_config or self.config.play
        self.enable_resign = enable_resign
        self.api = api or ReversiModelAPI(self.config, self.model)

        # key=(own, enemy, action)
        mtcs_info = mtcs_info or self.create_mtcs_info()
        self.var_n, self.var_w, self.var_p = mtcs_info

        self.expanded = set(self.var_p.keys())
        self.now_expanding = set()
        self.prediction_queue = Queue(self.play_config.prediction_queue_size)
        self.sem = asyncio.Semaphore(self.play_config.parallel_search_num)

        self.moves = []
        self.loop = asyncio.get_event_loop()
        self.running_simulation_num = 0
        self.callback_in_mtcs = None

        self.thinking_history = {}  # for fun
        self.resigned = False
        self.requested_stop_thinking = False
        self.solver = self.create_solver() 
开发者ID:mokemokechicken,项目名称:reversi-alpha-zero,代码行数:34,代码来源:player.py

示例13: unqueue

# 需要导入模块: from asyncio import queues [as 别名]
# 或者: from asyncio.queues import Queue [as 别名]
def unqueue(cmd, pld):
    """
    :param cmd: The command object referenced in the command.
    :type cmd: sigma.core.mechanics.command.SigmaCommand
    :param pld: The payload with execution data and details.
    :type pld: sigma.core.mechanics.payload.CommandPayload
    """
    if pld.args:
        if pld.msg.author.voice:
            same_bound = True
            if pld.msg.guild.voice_client:
                if pld.msg.guild.voice_client.channel.id != pld.msg.author.voice.channel.id:
                    same_bound = False
            if same_bound:
                if pld.msg.guild.voice_client:
                    queue = cmd.bot.music.get_queue(pld.msg.guild.id)
                    if not queue.empty():
                        try:
                            order_num = int(pld.args[0])
                            if order_num >= 1:
                                order_num -= 1
                            queue_list = await cmd.bot.music.listify_queue(queue)
                            queue_size = len(queue_list)
                            if order_num <= queue_size - 1:
                                item = queue_list[order_num]
                                is_mod = pld.msg.author.guild_permissions.manage_guild
                                is_req = item.requester.id == pld.msg.author.id
                                if is_mod or is_req:
                                    queue_list.remove(item)
                                    new_queue = Queue()
                                    for list_item in queue_list:
                                        await new_queue.put(list_item)
                                    cmd.bot.music.queues.update({pld.msg.guild.id: new_queue})
                                    response = ok(f'Removed {item.title}.')
                                    requester = f'{pld.msg.author.name}#{pld.msg.author.discriminator}'
                                    response.set_author(name=requester, icon_url=user_avatar(pld.msg.author))
                                else:
                                    auth_deny_desc = f'Sorry, {pld.msg.author.name}. To remove a song you need to be'
                                    auth_deny_desc += ' the person who requested it, or have the Manage Server'
                                    auth_deny_desc += f' permission on {pld.msg.guild.name}.'
                                    response = discord.Embed(color=0xBE1931)
                                    response.add_field(name='⛔ Access Denied', value=auth_deny_desc)
                            else:
                                response = error('Input out of range.')
                        except ValueError:
                            response = error('Invalid input. Numbers only.')
                    else:
                        response = error('The queue is empty.')
                else:
                    response = error('I am not connected to any channel.')
            else:
                response = error('You are not in my voice channel.')
        else:
            response = error('You are not in a voice channel.')
    else:
        response = error('Nothing inputted.')
    await pld.msg.channel.send(embed=response) 
开发者ID:lu-ci,项目名称:apex-sigma-core,代码行数:59,代码来源:unqueue.py


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