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