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


Python Dispatcher.stop方法代码示例

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


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

示例1: EmonHub

# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import stop [as 别名]
def EmonHub():
    
    # Load settings
    settings = ConfigObj("emonhub.conf", file_error=True)
    
    # Create queue for node packets
    queue = Queue.Queue(0)

    # Create and start serial listener
    a = Listener(queue,settings)
    a.start()
    
    # Create and start http dispatcher
    b = Dispatcher(queue,settings)
    b.start()

    while 1:
        try:
            time.sleep(0.1)
        except KeyboardInterrupt:
            print "Stopping threads"
            a.stop = True
            b.stop = True
            break
开发者ID:BuloZB,项目名称:development,代码行数:26,代码来源:03.py

示例2: Client

# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher 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

示例3: stapLab

# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import stop [as 别名]
class stapLab():
	def __init__(self,
				logStream	= (lambda _: None)
		):
		self.log		= logStream
		self.options		= self.parseargs()
		if self.options['verbose']:
			self.log	= print
		self.log(self.options)
		self.dispatcher		= Dispatcher(	registerCallbackFunc	= self.registerGUIcallback,
							args			= {
											'target-pid' 	: self.options['target-pid'],	
											'logStream'	: self.log,
											'hardFail'	: True,
											'followChildren': self.options['follow_children']
										}
						)
		self.timers		= []
		self.start()

	def parseargs(self):
		# parse args
		#TODO:
		# subargument structure so we can set individual options to each module, e.g.:
		# stapLab tid moduleA optionA1 optionB1 moduleB optionA2 optionB2
		# stapLab [-f] tid [module [option]]
		# -> Theoretically this could also be done by just simply copying an existing module and quickly modifiying the sourcecode
		# the advantage of this would be that we keep program complexity lower and it is more powerful to do it in code, 
		# compared to using switches and the cli parameters.
		parser = argparse.ArgumentParser(description='staplab - systemtap module dispatcher and data visualizer')
		parser.add_argument('target-pid', type=int, metavar="target_pid",
					help='target process ID. Must be greater than zero.')
		parser.add_argument('modules', type=str, nargs="+", metavar="module",default=['dummy'], 
					help='module to be dispatched')
		parser.add_argument('-f','--follow-children', action='store_true',
					help='if a process forks, include children to the tapset')
		parser.add_argument('-d','--hardFail', action='store_true',
					help='fail hard if Module cannot be loaded, i.e. quit and don\'t continue loading other modules')
		parser.add_argument('-v','--verbose', action='store_true',
					help='be verbose about what is going on internally')

		args = vars(parser.parse_args())
		return args

	def registerGUIcallback(self,func,timerInterval=20):
		fig	= pl.figure()
		self.log("set timer for %s" % str(func))
		def guiCallBack(func,figure):
			try:
				func(figure)
				#manager = pl.get_current_fig_manager()
				#manager.canvas.draw()
			except KeyboardInterrupt:
				self.stop()
		timer	= fig.canvas.new_timer(interval = timerInterval)
		timer.add_callback(guiCallBack,func,fig)
		timer.start()
		self.timers	+= [timer]

	def start(self):
		try:
			self.dispatcher.dispatchStapLabModuleAll(modules=self.options['modules'], target=self.options['target-pid'])
		except ImportError as err:
			self.log("error while loading a module: %s" % str(err))
			raise
		self.log("entering stapLab mainLoop")
		
		# wait for dispatcher to launch at least one module
		while self.dispatcher.stapLabModules == 0:
			sleep(1)
		
		# now run until we have no modules left to process
		while len(self.dispatcher.stapLabModules) > 0:
			try:
				# we do this so we can catch KeyboardInterrupts better
				pl.show()
				sleep(0.1)
			except KeyboardInterrupt:
				self.stop()
			except:
				self.log("error in stapLab mainLoop")
				raise
		self.log("leaving stapLab mainLoop")

	def stop(self):
		self.log("stapLab.stop()")
		self.dispatcher.stop()
		sys.exit(0)
开发者ID:psychophoniac,项目名称:staplab,代码行数:90,代码来源:staplab.py

示例4: Client

# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher 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


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