Python asyncio.queues.Queue() Examples
The following are 14
code examples of asyncio.queues.Queue().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
asyncio.queues
, or try the search function
.
Example #1
Source File: main.py From cchess-zero with MIT License | 6 votes |
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
Example #2
Source File: main_tf2.py From cchess-zero with MIT License | 6 votes |
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
Example #3
Source File: player_connect4.py From connect4-alpha-zero with MIT License | 6 votes |
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
Example #4
Source File: single.py From parade with MIT License | 6 votes |
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
Example #5
Source File: music.py From apex-sigma-core with GNU General Public License v3.0 | 6 votes |
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
Example #6
Source File: google_report_state.py From hass-nabucasa with GNU General Public License v3.0 | 5 votes |
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)
Example #7
Source File: verify.py From bandersnatch with Academic Free License v3.0 | 5 votes |
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) )
Example #8
Source File: music.py From apex-sigma-core with GNU General Public License v3.0 | 5 votes |
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
Example #9
Source File: pool.py From ant_nest with GNU Lesser General Public License v3.0 | 5 votes |
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
Example #10
Source File: pool.py From ant_nest with GNU Lesser General Public License v3.0 | 5 votes |
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()
Example #11
Source File: idxdumper.py From dumpall with MIT License | 5 votes |
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
Example #12
Source File: dsdumper.py From dumpall with MIT License | 5 votes |
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()
Example #13
Source File: player.py From reversi-alpha-zero with MIT License | 5 votes |
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()
Example #14
Source File: unqueue.py From apex-sigma-core with GNU General Public License v3.0 | 4 votes |
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)