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


Python queue.SimpleQueue方法代码示例

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


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

示例1: __init__

# 需要导入模块: import queue [as 别名]
# 或者: from queue import SimpleQueue [as 别名]
def __init__(self, bus, org, interface):
        self.bus = bus
        self.dbus_org = org
        self.dbus_interface = interface
        self._sent = False
        self._data = {'cmd': None}
        self.eventQueue = SimpleQueue()
        self.daemon = self._get_daemon(bus, org, interface)
        self.__async_thread = None

        logger.debug("%s daemon loaded - version :  %s" %
                     (interface, self.daemon.GetVersion())) 
开发者ID:manatools,项目名称:dnfdragora,代码行数:14,代码来源:dnfd_client.py

示例2: download_file

# 需要导入模块: import queue [as 别名]
# 或者: from queue import SimpleQueue [as 别名]
def download_file(url: str, out_path: str = None, buffer_size: int = 10*(1024**2)):
    data = Queue()
    def _download():
        b = data.get()
        with open(out_path or url.split('/')[-1], 'wb') as o:
            while b:
                o.write(b)
                b = data.get()
    
    s = ssl.SSLContext()
    f = req.urlopen(url, context=s)
    th = Thread(target=_download)
    th.start()
    b = f.read(buffer_size)
    while b:
        data.put(b)
        b = f.read(buffer_size)
    data.put([])
    th.join() 
开发者ID:hujinsen,项目名称:StarGAN-Voice-Conversion,代码行数:21,代码来源:download.py

示例3: __init__

# 需要导入模块: import queue [as 别名]
# 或者: from queue import SimpleQueue [as 别名]
def __init__(self, max_workers=None, thread_name_prefix='',
                 initializer=None, initargs=()):
        """Initializes a new ThreadPoolExecutor instance.

        Args:
            max_workers: The maximum number of threads that can be used to
                execute the given calls.
            thread_name_prefix: An optional name prefix to give our threads.
            initializer: An callable used to initialize worker threads.
            initargs: A tuple of arguments to pass to the initializer.
        """
        if max_workers is None:
            # Use this number because ThreadPoolExecutor is often
            # used to overlap I/O instead of CPU work.
            max_workers = (os.cpu_count() or 1) * 5
        if max_workers <= 0:
            raise ValueError("max_workers must be greater than 0")

        if initializer is not None and not callable(initializer):
            raise TypeError("initializer must be a callable")

        self._max_workers = max_workers
        self._work_queue = queue.SimpleQueue()
        self._threads = set()
        self._broken = False
        self._shutdown = False
        self._shutdown_lock = threading.Lock()
        self._thread_name_prefix = (thread_name_prefix or
                                    ("ThreadPoolExecutor-%d" % self._counter()))
        self._initializer = initializer
        self._initargs = initargs 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:33,代码来源:thread.py

示例4: run_all

# 需要导入模块: import queue [as 别名]
# 或者: from queue import SimpleQueue [as 别名]
def run_all(folder, s_target):
    sql_queue = SimpleQueue()
    size = 0
    for filename in glob.iglob(f'{folder}/**/*.sql', recursive=True):
        sql_queue.put(get_sql(filename))
        size += 1
    num_tries = 0
    max_tries = size * 2
    while not sql_queue.empty() and num_tries < max_tries:
        try:
            sql = sql_queue.get()
            s_target.execute(sql)
            s_target.commit()
            num_tries = 0
        except ProgrammingError as e:
            message = str(e.orig).strip()
            if 'relation' in message and 'does not exist' in message:
                s_target.rollback()
                print(f'Object does not exist yet: {message}. Re-queueing...')
                sql_queue.put(sql)
                num_tries += 1
            else:
                raise
    if num_tries >= max_tries:
        print(f'Number of attempts exceeded configured threshold of {max_tries}')
        sys.exit(1) 
开发者ID:In2ItChicago,项目名称:In2ItChicago,代码行数:28,代码来源:deploy.py

示例5: __init__

# 需要导入模块: import queue [as 别名]
# 或者: from queue import SimpleQueue [as 别名]
def __init__(self, rpc):
        super(GcRecorder, self).__init__()
        self.should_stop = False
        L.debug('session:{} initializing gc recorder'.format(rpc.session_id))
        self.record_rpc = rpc
        self.gc_recorder = dict()
        self.gc_queue = SimpleQueue()
        if "EGGROLL_GC_DISABLE" in os.environ and os.environ["EGGROLL_GC_DISABLE"] == '1':
            L.info("global gc is disable, "
                  "will not execute gc but only record temporary RollPair during the whole session")
        else:
            self.gc_thread = Thread(target=self.run, daemon=True)
            self.gc_thread.start()
            L.debug("starting gc_thread......") 
开发者ID:WeBankFinTech,项目名称:eggroll,代码行数:16,代码来源:gc_utils.py

示例6: _setup_logging_queue

# 需要导入模块: import queue [as 别名]
# 或者: from queue import SimpleQueue [as 别名]
def _setup_logging_queue(*handlers: Handler) -> QueueHandler:
    """Create a new LocalQueueHandler and start an associated QueueListener.
    """
    queue: Queue = Queue()
    queue_handler = LocalQueueHandler(queue)

    serving_listener = QueueListener(queue, *handlers, respect_handler_level=True)
    serving_listener.start()

    return queue_handler 
开发者ID:pgjones,项目名称:quart,代码行数:12,代码来源:logging.py

示例7: _setup_queues

# 需要导入模块: import queue [as 别名]
# 或者: from queue import SimpleQueue [as 别名]
def _setup_queues(self):
        self._inqueue = self._ctx.SimpleQueue()
        self._outqueue = self._ctx.SimpleQueue()
        self._quick_put = self._inqueue._writer.send
        self._quick_get = self._outqueue._reader.recv 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:7,代码来源:pool.py

示例8: __init__

# 需要导入模块: import queue [as 别名]
# 或者: from queue import SimpleQueue [as 别名]
def __init__(self, *, reader, loop: asyncio.AbstractEventLoop, executor):
        super().__init__(loop=loop, executor=executor)
        self.reader = reader
        self.queue = SimpleQueue()
        self.event = asyncio.Event()
        self.lock = asyncio.Lock()
        self.closed = False

        self._loop.create_task(self._exec(self._reader)) 
开发者ID:mosquito,项目名称:cysystemd,代码行数:11,代码来源:async_reader.py

示例9: __init__

# 需要导入模块: import queue [as 别名]
# 或者: from queue import SimpleQueue [as 别名]
def __init__(self, processes=None, initializer=None, initargs=(),
                 maxtasksperchild=None, context=None):
        self._ctx = context or get_context()
        self._setup_queues()
        self._taskqueue = queue.SimpleQueue()
        self._cache = {}
        self._state = RUN
        self._maxtasksperchild = maxtasksperchild
        self._initializer = initializer
        self._initargs = initargs

        if processes is None:
            processes = os.cpu_count() or 1
        if processes < 1:
            raise ValueError("Number of processes must be at least 1")

        if initializer is not None and not callable(initializer):
            raise TypeError('initializer must be a callable')

        self._processes = processes
        self._pool = []
        self._repopulate_pool()

        self._worker_handler = threading.Thread(
            target=Pool._handle_workers,
            args=(self._cache, self._taskqueue, self._ctx, self.Process,
                  self._processes, self._pool, self._inqueue, self._outqueue,
                  self._initializer, self._initargs, self._maxtasksperchild,
                  self._wrap_exception)
            )
        self._worker_handler.daemon = True
        self._worker_handler._state = RUN
        self._worker_handler.start()

        self._task_handler = threading.Thread(
            target=Pool._handle_tasks,
            args=(self._taskqueue, self._quick_put, self._outqueue,
                  self._pool, self._cache)
            )
        self._task_handler.daemon = True
        self._task_handler._state = RUN
        self._task_handler.start()

        self._result_handler = threading.Thread(
            target=Pool._handle_results,
            args=(self._outqueue, self._quick_get, self._cache)
            )
        self._result_handler.daemon = True
        self._result_handler._state = RUN
        self._result_handler.start()

        self._terminate = util.Finalize(
            self, self._terminate_pool,
            args=(self._taskqueue, self._inqueue, self._outqueue, self._pool,
                  self._worker_handler, self._task_handler,
                  self._result_handler, self._cache),
            exitpriority=15
            ) 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:60,代码来源:pool.py


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