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


Python Monitor.stop方法代码示例

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


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

示例1: test_stop_personal_cloud

# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import stop [as 别名]
    def test_stop_personal_cloud(self):

        monitor = Monitor(self.personal_cloud)
        print "try stop stop"
        monitor.start()
        # time.sleep(5)
        monitor.stop()
开发者ID:2XL,项目名称:rmq_monitor,代码行数:9,代码来源:monitor_test.py

示例2: test_emit_metric_to_manager

# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import stop [as 别名]
    def test_emit_metric_to_manager(self):
        monitor = Monitor(personal_cloud=self.personal_cloud, hostname=socket.gethostname())
        print "try emit metric to manager"
        monitor.start()

        monitor.emit()

        monitor.stop()
开发者ID:2XL,项目名称:rmq_monitor,代码行数:10,代码来源:monitor_test.py

示例3: Client

# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import stop [as 别名]

#.........这里部分代码省略.........
            tp={'url':uri}
            resume_data=self._cache.get_resume(info_hash=Cache.hash_from_magnet(uri))
            if resume_data:
                tp['resume_data']=resume_data

        elif os.path.isfile(uri):
            if os.access(uri,os.R_OK):
                info = lt.torrent_info(uri)
                tp= {'ti':info}
                resume_data= self._cache.get_resume(info_hash=str(info.info_hash()))
                if resume_data:
                    tp['resume_data']=resume_data
            else:
                raise ValueError('Invalid torrent path %s' % uri)
        else:
            raise ValueError("Invalid torrent %s" %uri)
        
        tp.update(self.torrent_paramss)
        self._th = self._ses.add_torrent(tp)
        

        for tr in self.INITIAL_TRACKERS:
            self._th.add_tracker({'url':tr})

        self._th.set_sequential_download(True)
        self._th.force_reannounce()
        self._th.force_dht_announce()

        self._monitor.start()
        self._dispatcher.do_start(self._th, self._ses)
        self.server.run()

        
    def stop(self):
        """
        Función encargada de de detener el torrent y salir
        """
        self._dispatcher.stop()
        self._dispatcher.join()
        self._monitor.stop()
        self.server.stop()
        self._dispatcher.stop()
        if self._ses:
            self._ses.pause()
            if self._th:
                self.save_resume()
            self.save_state()
        self._stop_services()
        self._ses.remove_torrent(self._th, self.auto_delete)
        del self._ses
        self.closed = True

    def _start_services(self):
        """
        Función encargada de iniciar los servicios de libtorrent: dht, lsd, upnp, natpnp
        """
        self._ses.add_dht_router("router.bittorrent.com",6881)
        self._ses.add_dht_router("router.bitcomet.com",554)
        self._ses.add_dht_router("router.utorrent.com",6881)
        self._ses.start_dht()
        self._ses.start_lsd()
        self._ses.start_upnp()
        self._ses.start_natpmp()
        
        
    def _stop_services(self):
开发者ID:SpankyEsse,项目名称:plugin.video.streamondemand,代码行数:70,代码来源:client.py

示例4: Mediaplat

# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import stop [as 别名]
class Mediaplat(object):
    """ Daemonize Class """

    def __init__(self):
        """ 
        Constructor of Daemon Class
        """
        # register signal handlers
        signal.signal(signal.SIGTSTP, signal.SIG_IGN)
        signal.signal(signal.SIGTTIN, signal.SIG_IGN)
        signal.signal(signal.SIGTTOU, signal.SIG_IGN)
        signal.signal(signal.SIGINT,  self.__signal_handler_terminate)
        signal.signal(signal.SIGTERM, self.__signal_handler_terminate)

        try:
            self.server = ThreadedUnixSocketServer(SOCKET_FILE, 
                ThreadedUnixSocketRequestHandler)
        except:
            log.error('address already in use')
            sys.exit(1)

    def __signal_handler_terminate(self, signalnum, frame):
        """ 
        Signal handler for terminate signals.

        Signal handler for the "signal.SIGTERM" signal. Raise a "SystemExit"
        exception to do something for that signal
        """
        log.warning("Terminating on signal %(signalnum)r" % locals())
        raise KeyboardInterrupt


    def run(self, options):
        """ 
        Beginning monitor thread. 
        Sleep and wait for interrupt. 
        """
        # Start plugin manager
        plugin_manager.load_all_plugins()
        # Start monitor thread
        paths = settings.get('core', 'base').split(',')

        content.set_push_func(plugin_manager.push_queue)
        if options.rebuild:
            content.rebuild()

        self.monitor = Monitor(paths)
        #self.monitor.set_push_queue_func(plugin_manager.push_queue)
        self.monitor.start()

        # Register bonjour
        if settings.get('core', 'aggregation') == 'True':
            self.bonjour = Bonjour()
            self.bonjour.register(socket.gethostname(), '_mediaplat._tcp', 9020)

        self.server.serve_forever()

    def stop(self):
        """ 
        stop the server and remove socket file.
        Terminate all children threads and wait until terminate. 
        """
        try:
            os.unlink(SOCKET_FILE)
        except:
            pass

        if getattr(self, 'bonjour', None):
            self.bonjour.unregister()

        self.server.shutdown()

        self.monitor.stop()
        plugin_manager.stop() 

    def __enter__(self):
        """ 
        Entry point of Daemon Class for python 'with' statement
        """
        return self


    def __exit__(self, exc_type, exc_value, traceback):
        """ 
        Clean up function of Daemon Class for python 'with' statement
        """
        self.stop()

    @classmethod
    def request(self, send_data, mode = 0):
        """ request daemon function

            @type  send_data: dict
            @param send_data: parameters related with service and action
            @type  mode: int 
            @param mode: request & response type
            @rtype: dict
            @return: {"error": int, "return_date": dict} dictionary
        """
        try:
#.........这里部分代码省略.........
开发者ID:mattli001,项目名称:mediaplat,代码行数:103,代码来源:mediaplat.py

示例5: APIServer

# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import stop [as 别名]

#.........这里部分代码省略.........
        ]

        settings = dict(
            template_path=os.path.join(AppFolders.appBase(), "templates"),
            static_path=os.path.join(AppFolders.appBase(), "static"),
            static_url_prefix=self.webroot + "/static/",
            debug=True,
            #autoreload=False,
            login_url=self.webroot + "/login",
            cookie_secret=self.config['security']['cookie_secret'],
            xsrf_cookies=True,
        )

        tornado.web.Application.__init__(self, handlers, **settings)

        if not opts.no_monitor:     
            logging.debug("Going to scan the following folders:")
            for l in self.config['general']['folder_list']:
                logging.debug(u"   {0}".format(repr(l)))

            self.monitor = Monitor(self.dm, self.config['general']['folder_list'])
            self.monitor.start()
            self.monitor.scan()
            
        self.bookmarker = Bookmarker(self.dm)
        self.bookmarker.start()

        if opts.launch_browser and self.config['general']['launch_browser']:
            if ((platform.system() == "Linux" and os.environ.has_key('DISPLAY')) or
                    (platform.system() == "Darwin" and not os.environ.has_key('SSH_TTY')) or
                    platform.system() == "Windows"):
                webbrowser.open("http://localhost:{0}".format(self.port), new=0)

    def rebuild(self):
        # after restart, purge the DB
        sys.argv.insert(1, "--_resetdb_and_run")
        self.restart()
        
    def restart(self):
        self.shutdown()
        executable = sys.executable
            
        new_argv = ["--nobrowser"]
        if self.opts.quiet:
            new_argv.append("-q")
        if self.opts.debug:
            new_argv.append("-d")
        if  "--_resetdb_and_run" in sys.argv:
            new_argv.append("--_resetdb_and_run")

        if getattr(sys, 'frozen', None):
            # only keep selected args
            new_argv.insert(0, os.path.basename(executable) )
            os.execv(executable, new_argv)
        else:
            new_argv.insert(0, os.path.basename(sys.argv[0]) )
            os.execl(executable, executable, *new_argv)    
        
    def shutdown(self):
        
        MAX_WAIT_SECONDS_BEFORE_SHUTDOWN = 3

        logging.info('Initiating shutdown...')
        self.monitor.stop()
        self.bookmarker.stop()
     
        logging.info('Will shutdown ComicStreamer in maximum %s seconds ...', MAX_WAIT_SECONDS_BEFORE_SHUTDOWN)
        io_loop = tornado.ioloop.IOLoop.instance()
     
        deadline = time.time() + MAX_WAIT_SECONDS_BEFORE_SHUTDOWN
     
        def stop_loop():
            now = time.time()
            if now < deadline and (io_loop._callbacks or io_loop._timeouts):
                io_loop.add_timeout(now + 1, stop_loop)
            else:
                io_loop.stop()
                logging.info('Shutdown complete.')
        stop_loop()
        
    def log_request(self, handler):
        if handler.get_status() < 300:
            log_method = logging.debug
        elif handler.get_status() < 400:
            log_method = logging.debug
        elif handler.get_status() < 500:
            log_method = logging.warning
        else:
            log_method = logging.error
        request_time = 1000.0 * handler.request.request_time()
        log_method("%d %s %.2fms", handler.get_status(),
                   handler._request_summary(), request_time)
        
    def run(self):
        tornado.ioloop.IOLoop.instance().start()
    
    def runInThread(self):
        import threading
        t = threading.Thread(target=self.run)
        t.start()
开发者ID:Kalinon,项目名称:ComicStreamer,代码行数:104,代码来源:server.py

示例6: Client

# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import stop [as 别名]

#.........这里部分代码省略.........
        #Esperamos a lo metadatos
        while not self.has_meta:
            time.sleep(1)
        files = []

        #Comprobamos que haya archivos de video
        if self.files:
            #Creamos el dict con los archivos
            for file in self.files:
                n = file.path
                u = "http://" + self.ip + ":" + str(self.port) + "/" + urllib.quote(n)
                s = file.size
                files.append({"name":n,"url":u,"size":s})

        return files

    def announce_torrent(self):
        self._th.force_reannounce()
        self._th.force_dht_announce()

    def _auto_shutdown(self, *args, **kwargs):
        if self.file and self.file.cursor:
            self.last_connect = time.time()
            self.connected = True

        if self.is_playing_fnc and self.is_playing_fnc():
            self.last_connect = time.time()
            self.connected = True

        if self.auto_shutdown:
            #shudown por haber cerrado el reproductor
            if self.connected and self.is_playing_fnc and not self.is_playing_fnc():
                if time.time() - self.last_connect - 1 > self.timeout:
                    self.stop()

            #shutdown por no realizar ninguna conexion
            if (not self.file or not self.file.cursor) and self.start_time and self.wait_time and not self.connected:
                if time.time() - self.start_time - 1 > self.wait_time:
                    self.stop()

            #shutdown tras la ultima conexion
            if (not self.file or not self.file.cursor) and self.timeout and self.connected and not self.is_playing_fnc:
                if time.time() - self.last_connect - 1 > self.timeout:
                    self.stop()

    def save_state(self):
        state=self._ses.save_state()
        with open(os.path.join(self.temp_path,self.state_file), 'wb') as f:
            pickle.dump(state,f)

     
    def _update_ready_pieces(self, alert_type, alert):
        if alert_type == 'read_piece_alert' and self.file:
            self.file.update_piece(alert.piece, alert.buffer)
            
            
    def _check_meta(self):
        if self.status.state>=3 and  self.status.state <= 5 and not self.has_meta:

            #Guardamos los metadatos
            self.meta = self._th.get_torrent_info()

            #Obtenemos la lista de archivos del meta
            fs=self.meta.files()
            files=fs if isinstance(fs, list) else [fs.at(i) for i in xrange(fs.num_files())]
开发者ID:neozeta,项目名称:plugin.video.streamondemand,代码行数:69,代码来源:client.py


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