當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。