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


Python Queue.Queue方法代码示例

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


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

示例1: __init__

# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import Queue [as 别名]
def __init__(self, maxsize = 0, worker_threads = 1, unpack_threads = 1, inspect_threads = 1, idb_threads = 1, bindiff_threads = 1):
        """
            Create a Bass server.
            :param maxsize: Maximum size of the job queue. If the queue is full, jobs are rejected. 0 means unlimited.
            :param threads: Number of worker threads to use.
        """

        #TODO: Access to jobs is not threadsafe
        self.job_counter = 1
        self.jobs = {}
        self.jobs_lock = Lock()
        self.input_queue = Queue(maxsize)
        self.unpack_executor = ThreadPoolExecutor(max_workers = unpack_threads)
        self.inspect_executor = ThreadPoolExecutor(max_workers = inspect_threads)
        self.idb_executor = ThreadPoolExecutor(max_workers = idb_threads)
        self.bindiff_executor = ThreadPoolExecutor(max_workers = bindiff_threads)
        self.inspectors = [MagicInspector(), SizeInspector(), FileTypeInspector()]
        self.terminate = False
        self.threads = [start_thread(self.process_job) for _ in range(worker_threads)]
        self.bindiff = BindiffClient(urls = [BINDIFF_SERVICE_URL])
        self.whitelist = FuncDB(FUNCDB_SERVICE_URL)
        self.ida = IdaClient(urls = [IDA_SERVICE_URL]) 
开发者ID:Cisco-Talos,项目名称:BASS,代码行数:24,代码来源:core.py

示例2: sendHciCommand

# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import Queue [as 别名]
def sendHciCommand(self, opcode, data, timeout=2):
        """
        Send an arbitrary HCI packet by pushing a send-task into the
        sendQueue. This function blocks until the response is received
        or the timeout expires. The return value is the Payload of the
        HCI Command Complete Event which was received in response to
        the command or None if no response was received within the timeout.
        """

        queue = Queue.Queue(1)
        try:
            self.sendQueue.put((opcode, data, queue), timeout=timeout)
            return queue.get(timeout=timeout)
        except Queue.Empty:
            log.warn("sendHciCommand: waiting for response timed out!")
            return None
        except Queue.Full:
            log.warn("sendHciCommand: send queue is full!")
            return None 
开发者ID:francozappa,项目名称:knob,代码行数:21,代码来源:core.py

示例3: recvPacket

# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import Queue [as 别名]
def recvPacket(self, timeout=None):
        """
        This function polls the recvQueue for the next available HCI
        packet and returns it. The function checks whether it is called
        from the sendThread or any other thread and respectively chooses
        either the sendThreadrecvQueue or the recvQueue.

        The recvQueue is filled by the recvThread. If the queue fills up
        the recvThread empties the queue (unprocessed packets are lost).
        The recvPacket function is meant to receive raw HCI packets in
        a blocking manner. Consider using the registerHciCallback()
        functionality as an alternative which works asynchronously.
        """

        if not self.check_running():
            return None

        try:
            return self.recvQueue.get(timeout=timeout)
        except Queue.Empty:
            return None 
开发者ID:francozappa,项目名称:knob,代码行数:23,代码来源:core.py

示例4: __init__

# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import Queue [as 别名]
def __init__(self, batch_size, input_length, nthreads=6, web_viz=False):
        super(RLDataIter, self).__init__()
        self.batch_size = batch_size
        self.input_length = input_length
        self.env = [self.make_env() for _ in range(batch_size)]
        self.act_dim = self.env[0].action_space.n

        self.state_ = None

        self.reset()

        self.provide_data = [mx.io.DataDesc('data', self.state_.shape, np.uint8)]

        self.web_viz = web_viz
        if web_viz:
            self.queue = queue.Queue()
            self.thread = Thread(target=make_web, args=(self.queue,))
            self.thread.daemon = True
            self.thread.start()

        self.nthreads = nthreads
        if nthreads > 1:
            self.pool = multiprocessing.pool.ThreadPool(6) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:25,代码来源:rl_data.py

示例5: bThread

# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import Queue [as 别名]
def bThread(iplist):

    threadl = []
    queue = Queue.Queue()
    for host in iplist:
        queue.put(host)

    for x in xrange(0, int(sys.argv[2])):
        threadl.append(tThread(queue))

    for t in threadl:
        t.start()
    for t in threadl:
        t.join()

#create thread 
开发者ID:duchengyao,项目名称:hkdvr_login,代码行数:18,代码来源:dvrlogin.py

示例6: bThread

# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import Queue [as 别名]
def bThread(iplist):

    threadl = []
    queue = Queue.Queue()
    for host in iplist:
        queue.put(host)

    for x in xrange(0, int(sys.argv[1])):
        threadl.append(tThread(queue))

    for t in threadl:
        t.start()
    for t in threadl:
        t.join()

#create thread 
开发者ID:duchengyao,项目名称:hkdvr_login,代码行数:18,代码来源:check.py

示例7: threaded_generator

# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import Queue [as 别名]
def threaded_generator(generator, num_cached=10):
    # this code is written by jan Schluter
    # copied from https://github.com/benanne/Lasagne/issues/12
    import Queue
    queue = Queue.Queue(maxsize=num_cached)
    sentinel = object()  # guaranteed unique reference

    # define producer (putting items into queue)
    def producer():
        for item in generator:
            queue.put(item)
        queue.put(sentinel)

    # start producer (in a background thread)
    import threading
    thread = threading.Thread(target=producer)
    thread.daemon = True
    thread.start()

    # run as consumer (read items from queue, in current thread)
    item = queue.get()
    while item is not sentinel:
        yield item
        queue.task_done()
        item = queue.get() 
开发者ID:Lasagne,项目名称:Recipes,代码行数:27,代码来源:generators.py

示例8: generate_in_background

# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import Queue [as 别名]
def generate_in_background(generator, num_cached=10):
    """
    Runs a generator in a background thread, caching up to `num_cached` items.
    """
    import Queue
    queue = Queue.Queue(maxsize=num_cached)
    sentinel = object()  # guaranteed unique reference

    # define producer (putting items into queue)
    def producer():
        for item in generator:
            queue.put(item)
        queue.put(sentinel)

    # start producer (in a background thread)
    import threading
    thread = threading.Thread(target=producer)
    thread.daemon = True
    thread.start()

    # run as consumer (read items from queue, in current thread)
    item = queue.get()
    while item is not sentinel:
        yield item
        item = queue.get() 
开发者ID:Lasagne,项目名称:Recipes,代码行数:27,代码来源:train_test.py

示例9: get_sizes

# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import Queue [as 别名]
def get_sizes(jsn):
   thrd = threading.current_thread()
   logging.info('starting thread '+str(thrd.ident)+' ...')
   try:
      while True:
         if queue.empty() == True: 
            break
         itm = queue.get()
         logging.info(str(thrd.ident)+' :' +str(itm))
         val = get_remote_size(itm)
         if val != None: jsn[itm]['objsize'] = val
         queue.task_done()
   except Queue.Empty: 
      pass
   logging.info('thread '+str(thrd.ident)+' done...') 
#get_sizes

#--------------------------------------------------------------------------------- 
开发者ID:HDFGroup,项目名称:hsds,代码行数:20,代码来源:get_s3_stats.py

示例10: extractInfo

# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import Queue [as 别名]
def extractInfo(self):
        try:
            while not self.exit:
                try:
                    frame = self.frame_queue.get(block=True, timeout=1)
                except queue.Empty:
                    print("Queue empty")
                    continue
                try:
                    # Publish new image
                    msg = self.bridge.cv2_to_imgmsg(frame, 'rgb8')
                    if not self.exit:
                        self.image_publisher.publish(msg)
                except CvBridgeError as e:
                    print("Error Converting cv image: {}".format(e.message))
                self.frame_num += 1
        except Exception as e:
            print("Exception after loop: {}".format(e))
            raise 
开发者ID:sergionr2,项目名称:RacingRobot,代码行数:21,代码来源:camera_node.py

示例11: _check_and_execute

# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import Queue [as 别名]
def _check_and_execute(self):
        wakeup_queue = self._wakeup_queue
        while 1:
            (next_expired_time, expired_timers) = self._get_expired_timers()
            for timer in expired_timers:
                try:
                    # Note, please make timer callback effective/short
                    timer()
                except Exception:
                    logging.error(traceback.format_exc())

            self._reset_timers(expired_timers)

            sleep_time = _calc_sleep_time(next_expired_time)
            try:
                wakeup = wakeup_queue.get(timeout=sleep_time)
                if wakeup is TEARDOWN_SENTINEL:
                    break
            except Queue.Empty:
                pass
        logging.info('TimerQueue stopped.') 
开发者ID:remg427,项目名称:misp42splunk,代码行数:23,代码来源:timer_queue.py

示例12: __init__

# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import Queue [as 别名]
def __init__(self, max_workers=None, thread_name_prefix=''):
        """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.
        """
        if max_workers is None:
            # Use this number because ThreadPoolExecutor is often
            # used to overlap I/O instead of CPU work.
            max_workers = (cpu_count() or 1) * 5
        if max_workers <= 0:
            raise ValueError("max_workers must be greater than 0")

        self._max_workers = max_workers
        self._work_queue = queue.Queue()
        self._idle_semaphore = threading.Semaphore(0)
        self._threads = set()
        self._shutdown = False
        self._shutdown_lock = threading.Lock()
        self._thread_name_prefix = (thread_name_prefix or
                                    ("ThreadPoolExecutor-%d" % self._counter())) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:25,代码来源:thread.py

示例13: __init__

# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import Queue [as 别名]
def __init__(self, stream, event):
        self.strm = stream
        self.que = Queue()
	self.event = event

        def populateQueue(stream, queue, event):
            while not event.is_set():
                line = stream.readline()
                if line:
                    queue.put(line)
                else:
		     break

        self.thr = Thread(target = populateQueue,
                args = (self.strm, self.que, self.event))
        self.thr.daemon = True
        self.thr.start() #start collecting lines from the stream 
开发者ID:jphfilm,项目名称:rpi-film-capture,代码行数:19,代码来源:nbstreamreader.py

示例14: bfs_print

# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import Queue [as 别名]
def bfs_print(root):
    print "*** bfs print ***"
    q = Queue()
    s_node=root
    q.put(s_node)
    seen_list = []

    while(not q.empty()):
        node=q.get() # removes
        print node.n_node_id
        if(node not in seen_list):
            seen_list.append(node)
        for child in node.children:
            if(child not in seen_list):
                q.put(child)
    print "---------------" 
开发者ID:arun1729,项目名称:road-network,代码行数:18,代码来源:Util.py

示例15: add_square_at

# 需要导入模块: import Queue [as 别名]
# 或者: from Queue import Queue [as 别名]
def add_square_at(root,nodeid):
    q = Queue()
    s_node=root
    q.put(s_node)
    seen_list = []

    while(not q.empty()):
        node=q.get() # removes
        if nodeid==node.n_node_id:
            node.add_square()
        else:
            if(node not in seen_list):
                seen_list.append(node)
            for child in node.children:
                if(child not in seen_list):
                    q.put(child) 
开发者ID:arun1729,项目名称:road-network,代码行数:18,代码来源:Util.py


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