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


Python Status.shutdown方法代码示例

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


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

示例1: BitcasaDownload

# 需要导入模块: from status import Status [as 别名]
# 或者: from status.Status import shutdown [as 别名]
class BitcasaDownload(object):
    def __init__(self, args, client, should_exit):
        log.debug("source dir: %s", args.src)
        log.debug("destination dir: %s", args.dst)
        log.debug("temp dir: %s", args.temp)
        log.debug("upload: %s", args.upload)
        if args.upload:
            log.debug("provider: %s", args.provider)
        log.debug("log dir: %s", args.logdir)
        log.debug("recursion: %s", args.rec)
        log.debug("depth: %s", args.depth)
        log.debug("max folder threads: %s", args.folderthreads)
        log.debug("max download threads: %s", args.threads)
        log.debug("progress: %s", args.progress)
        log.debug("silent queuer: %s", args.silentqueuer)
        log.debug("single: %s", args.single)

        #bittcasa base64 encdoded path
        self.basefolder = args.src
        if args.single:
            log.debug("Downloading single file. Setting max threads to 1")
            args.threads = 1
            args.folderthreads = 1

        self.args = args

        #Initialize
        self.should_exit = should_exit
        self.client = client
        self.session = requests.Session()
        self.results = results.Results(args.logdir, should_exit, args.nofilelog)

        # Threads        
        self.download_threads = []
        self.upload_threads = []
        self.copy_threads = []
        self.folder_threads = []

        self.status = Status(should_exit)
        self.shutdown_sent = False

    def shutdown(self):
        if not self.shutdown_sent:
            self.shutdown_sent = True
            self.status.shutdown()

    def get_status(self):
        return self.status

    def process(self, base=None):
        log.debug("Getting base folder")
        if self.args.upload and self.args.local and base is None:
            base = BitcasaFolder(None, "root", self.basefolder)
        else:
            remainingtries = 3
            apiratecount = 1
            while base is None and remainingtries > 0 and not self.should_exit.is_set():
                try:
                    base = self.client.get_folder(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 base folder %s. Will retry %s more times", e.code, remainingtries)

                    if remainingtries > 0:
                        time.sleep(10 * apiratecount)
                    else:
                        log.error("Error could not retrieve base folder")
                        return
        if self.should_exit.is_set():
            return
        log.debug("Queuing base folder")
        folder = {
            "folder": base,
            "path": "",
            "depth": 0
        }

        if self.args.upload:
            folder["folder_id"] = self.args.dst
        
        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")
#.........这里部分代码省略.........
开发者ID:reallistic,项目名称:BitcasaFileLister,代码行数:103,代码来源:bitcasadownload.py

示例2: Peer

# 需要导入模块: from status import Status [as 别名]
# 或者: from status.Status import shutdown [as 别名]

#.........这里部分代码省略.........
                            'filesize': filesize }
                self.rQueue.put( package )
                return RETURNCODES['errOk']
        except Exception as inst:
            logging.error ( 'Exception while inserting file: ' + str( type( inst ) ) )
    
    
    def remove( self, filename ):
        """Remove specified file from the network"""
        if not self.status.checkForFile( filename ):
            return RETURNCODES['errUnknownWarning']
            
        package = { 'packageType': 'command',
                    'command': 'remove',
                    'filename': filename }
        self.rQueue.put( package )
        return RETURNCODES['errOk']

    # --------------------------------
    # PRIVATE METHODS (IMPLEMENTATION)
    # --------------------------------

    def run( self ):
        """
        Run method called upon thread start
        Continuously processes requests or sends out file chunks
        """
        i = 1
        while True :
            try: 
                if not self.rQueue.empty():
                    # Process request in queue
                    package = self.rQueue.get()
                    if package == 'shutdown':
                        logging.info( 'Shutdown token found in rQueue' )
                        break
                    self.processRequest( package )
                elif self.joined and i == 0:
                    # Periodically query peers to get up-to-date statuses
                    self.massQuery()
                    i = (i + 1) % QUERYRATE
                elif self.joined:    
                    # Attemp to share a chunk with all active peers
                    self.shareChunks()
                    i = (i + 1) % QUERYRATE
                    time.sleep( 0.0005 )
            except Exception as inst:
                logging.error ( 'Exception in Peer run: ' + str( type( inst ) ) )


    def init( self, host, port, peers, dirName ):
        logging.info( 'Initializing new peer ' + self.getPeerKey( host, port ) )
        self.filesDir = dirName
        self.host = host
        self.port = port
        self.peers = peers
        self.peerKey = self.getPeerKey( host, port )
        self.activePeers = {}
        self.waitingQueries = []
        self.joined = False
        self.status = Status( self.peerKey )
        self.status.registerPeer( self.peerKey, {} )
        self.sender = Sender( self )
        self.rQueue = Queue()
        self.shutdownFlag = False
        self.start()
开发者ID:Arreth,项目名称:ECE454P1,代码行数:70,代码来源:peer.py


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