當前位置: 首頁>>代碼示例>>Python>>正文


Python Status.join_queues方法代碼示例

本文整理匯總了Python中status.Status.join_queues方法的典型用法代碼示例。如果您正苦於以下問題:Python Status.join_queues方法的具體用法?Python Status.join_queues怎麽用?Python Status.join_queues使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在status.Status的用法示例。


在下文中一共展示了Status.join_queues方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: BitcasaDownload

# 需要導入模塊: from status import Status [as 別名]
# 或者: from status.Status import join_queues [as 別名]

#.........這裏部分代碼省略.........
        
        step2_args = ( self.status, self.should_exit, self.results, self.args )
        download_args = ( self.status, self.should_exit, self.session, self.results, self.args)
        folder_args = ( self.status, self.results, self.args, self.should_exit )

        self.status.queue(folder)
        if not self.args.dryrun and not self.args.local:
            log.debug("Starting Downloaders")
            for qid in xrange(self.args.threads):
                qid += 1
                download_thread = threading.Thread(target=DownloadThread, args=download_args, name="Download %s" % qid)
                download_thread.daemon = True
                download_thread.start()
                self.download_threads.append(download_thread)
        
        log.debug("Starting Queuers")
        for qid in xrange(self.args.folderthreads):
            qid += 1
            folder_thread = threading.Thread(target=FolderThread, args=folder_args, name="Queuer %s" % qid)
            folder_thread.daemon = True
            folder_thread.start()
            self.folder_threads.append(folder_thread)

        if not self.args.dryrun and self.args.upload:
            log.debug("Starting Uploaders")
            for qid in xrange(self.args.threads):
                qid += 1
                upload_thread = threading.Thread(target=UploadThread, args=step2_args, name="Upload %s" % qid)
                upload_thread.daemon = True
                upload_thread.start()
                self.upload_threads.append(upload_thread)
        elif not self.args.dryrun and self.args.temp:
            log.debug("Starting Movers")
            for qid in xrange(self.args.threads):
                qid += 1
                copy_thread = threading.Thread(target=CopyThread, args=step2_args, name="Move %s" % qid)
                copy_thread.daemon = True
                copy_thread.start()
                self.copy_threads.append(copy_thread)
        
        if self.args.progress:
            self.status_thread = threading.Thread(target=self.status.StatusThread, args=(self.args.upload, self.args.temp, self.should_exit), name="Progress")
            self.status_thread.daemon = True
            self.status_thread.start()
        self.end_process()

    def process_single(self):
        log.debug("Getting file info")
        myfile = None
        if self.args.upload and self.args.local:
            size = 0
            name = ""
            try:
                if os.path.isdir(self.basefolder):
                    raise OSError("Incorrect file")
                size = os.path.getsize(self.basefolder)
                name = os.path.basename(self.basefolder)
            except OSError:
                log.exception("Error getting file")
                return
            myfile = BitcasaFile(None, self.basefolder, name, None, size)
            fold = BitcasaFolder(None, "root", "", items=[myfile])
        else:
            remainingtries = 3
            apiratecount = 1
            while myfile is None and remainingtries > 0 and not self.should_exit.is_set():
                try:
                    myfile = self.client.get_file_meta(self.basefolder)
                except BitcasaException as e:
                    remainingtries -= 1
                    if e.code == 9006:
                        apiratecount += 1
                        remainingtries += 1
                        log.warn("API rate limit reached. Will retry")
                    else:
                        log.warn("Couldn't get file %s. Will retry %s more times", e.code, remainingtries)

                    if remainingtries > 0:
                        time.sleep(10 * apiratecount)
                    else:
                        log.error("Error could not retrieve file")
                        return
            fold = BitcasaFolder(self.client, "root", "", items=[myfile])
        log.debug("Got file info")
        self.process(fold)

    def end_process(self):
        # Give the queuers time to catch up
        try:
            if not self.should_exit.is_set():
                time.sleep(10)
        except (KeyboardInterrupt, IOError):
            pass

        self.status.join_queues()
        log.debug("Finished waiting")

        #Log final speed and statistics
        if not self.args.dryrun:
            self.status.final_status(self.args.upload, self.args.temp, final=True)
開發者ID:reallistic,項目名稱:BitcasaFileLister,代碼行數:104,代碼來源:bitcasadownload.py


注:本文中的status.Status.join_queues方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。