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


Python Queue.Queue方法代码示例

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


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

示例1: main

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

    # Create Queue and redirect sys.stdout to this queue
    queue = Queue()
    sys.stdout = StdoutQueue(queue)

    # Start the main GUI class
    app = QtGui.QApplication(sys.argv)
    form = MainWindow()
    form.show()

    # Create thread that will listen for new strings in the queue. Upon new
    #   items, Receiver will emit a signal, which will be sent to the
    #   onDataReady method in the MainWindow class. The onDataReady method
    #   will add the string to the text editor in the GUI.
    thread = QtCore.QThread()
    receiver = Receiver(queue)
    receiver.signal.connect(form.onDataReady)
    receiver.moveToThread(thread)
    thread.started.connect(receiver.run)
    thread.start()

    sys.exit(app.exec_()) 
开发者ID:camisatx,项目名称:pySecMaster,代码行数:25,代码来源:main_gui.py

示例2: __init__

# 需要导入模块: from queue import Queue [as 别名]
# 或者: from queue.Queue import Queue [as 别名]
def __init__(self, queue, *args, **kwargs):
        """
        A QObject (to be run in a QThread) which sits waiting for data to come through a Queue.Queue().
        It blocks until data is available, and once it has got something from the queue, it sends
        it to the main GUI thread by emitting the pyqtSignal 'queuePutSignal'

        :type queue: Queue.queue
        """
        QObject.__init__(self, *args, **kwargs)
        self.queue = queue
        self.continueOperation = True 
开发者ID:NSchrading,项目名称:redditDataExtractor,代码行数:13,代码来源:main.py

示例3: main

# 需要导入模块: from queue import Queue [as 别名]
# 或者: from queue.Queue import Queue [as 别名]
def main():
    app = QApplication(sys.argv)
    rddtDataExtractor = loadState()
    if rddtDataExtractor is None:
        rddtDataExtractor = RedditDataExtractor()
    else:
        # If something weird happened to cause currentlyDownloading to be saved as True, set it back to False
        rddtDataExtractor.currentlyDownloading = False
        # reinstantiate the praw instance because it doesn't shelve properly
        # praw shelve issue causes http.validate_certs to be uninstantiated
        rddtDataExtractor._r = praw.Reddit(user_agent='Data Extractor for reddit v1.1 by /u/VoidXC')
        rddtDataExtractor._r.http.validate_certs = 'RedditDataExtractor/cacert.pem'

    queue = Queue()
    thread = QThread()
    recv = QueueMessageReceiver(queue)
    mainGUIWindow = RddtDataExtractorGUI(rddtDataExtractor, queue, recv)

    recv.queuePutSignal.connect(mainGUIWindow.append_text)
    recv.moveToThread(thread)
    thread.started.connect(recv.run)
    # Add clean up finished signals so the threads end appropriately when the program ends
    recv.finished.connect(thread.quit)
    recv.finished.connect(recv.deleteLater)
    thread.finished.connect(thread.deleteLater)

    # start the receiver
    thread.start()
    # show the GUI
    mainGUIWindow.show()
    # display Imgur API pop up if not hidden by user and client-id isn't set
    if rddtDataExtractor.showImgurAPINotification and rddtDataExtractor.imgurAPIClientID is None:
        mainGUIWindow.notifyImgurAPI()
    # and wait for the user to exit
    sys.exit(app.exec_()) 
开发者ID:NSchrading,项目名称:redditDataExtractor,代码行数:37,代码来源:main.py

示例4: __init__

# 需要导入模块: from queue import Queue [as 别名]
# 或者: from queue.Queue import Queue [as 别名]
def __init__(self):
        self.queue = Queue.Queue()
        with open(PROXY_PATH_REQUEST, 'r') as f:
            lines = f.readlines()
            self.len = len(lines)
            for line in lines:
                info = line.strip().split(',')
                proxy = {}
                if len(info) == 2:
                    proxy = {"http": "http://%s:%s" % (info[0], info[1]),
                             "https": "http://%s:%s" % (info[0], info[1])}
                elif len(info) == 4:
                    proxy = {"http": "http://%s:%s@%s:%s/" % (info[2], info[3], info[0], info[1]),
                             "https": "http://%s:%s@%s:%s/" % (info[2], info[3], info[0], info[1])}
                self.queue.put(proxy) 
开发者ID:DarkSand,项目名称:fetchman,代码行数:17,代码来源:proxy_pool.py

示例5: get_web_driver_pool

# 需要导入模块: from queue import Queue [as 别名]
# 或者: from queue.Queue import Queue [as 别名]
def get_web_driver_pool(num):
    driver_queue = Queue.Queue()
    i = 0
    while i < num:
        web = _get_base_driver()
        driver_queue.put(web)
        i += 1
    return driver_queue 
开发者ID:DarkSand,项目名称:fetchman,代码行数:10,代码来源:web_driver_pool.py

示例6: _run_threads

# 需要导入模块: from queue import Queue [as 别名]
# 或者: from queue.Queue import Queue [as 别名]
def _run_threads(self, command_strings, thread_class, display_percents=True):
        """
        This class creates and run threads of the provided type for each provided command
        :param command_strings: the list of commands to be run in the threads
        :type command_strings: list
        :param thread_class: the type of thread class to create
        :type thread_class: type Analysis.threads
        :param display_percents: to tell whether to display a log for 0% and 100% complete
        :type display_percents: bool
        """
        self.slate = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]
        if len(command_strings) < 11:
            # to avoid false progress display if not enough entries
            self.slate = [100, 50]
        self._exit_flag = 0
        # Create X number of threads
        self._thread_list = []
        self._total = len(command_strings)
        mark = 0
        for i in range(int(self._cpus)):
            mark += 1
            self._thread_list.append(
                "%s-%s-%s" % (thread_class.CLASS_ABREV, self._abrev, str(i + 1)))
            if mark >= self._total:
                break
        self._queue_lock = threading.Lock()
        self._work_queue = queue.Queue(len(command_strings))
        threads = []
        thread_id = 1

        # Generate the new threads
        for t_name in self._thread_list:
            thread = thread_class(thread_id, t_name, self)
            thread.start()
            threads.append(thread)
            thread_id += 1

        if display_percents:
            _logger.info('%s =>\t0%% of predictions performed (%i to be done)'
                         % (time.strftime("%m/%d/%Y %H:%M:%S"), self._total))

        # Fill the queue with the commands
        self._queue_lock.acquire()
        for word in command_strings:
            self._work_queue.put(word)
        self._queue_lock.release()

        # Wait for all jobs to finish (i.e. queue being empty)
        while not self._work_queue.empty():
            time.sleep(0.01)
            pass
        # Send exit signal
        self._exit_flag = 1

        # Wait for all threads to finish
        for t in threads:
            t.join()

        if display_percents:
            _logger.info('%s =>\t100%% of predictions performed' %
                         time.strftime("%m/%d/%Y %H:%M:%S")) 
开发者ID:nextgenusfs,项目名称:funannotate,代码行数:63,代码来源:funannotate-BUSCO2.py


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