本文整理汇总了Python中dispatcher.Dispatcher.do_start方法的典型用法代码示例。如果您正苦于以下问题:Python Dispatcher.do_start方法的具体用法?Python Dispatcher.do_start怎么用?Python Dispatcher.do_start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dispatcher.Dispatcher
的用法示例。
在下文中一共展示了Dispatcher.do_start方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Client
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import do_start [as 别名]
#.........这里部分代码省略.........
if resume_data:
tp['resume_data']=resume_data
elif uri.startswith('magnet:'):
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()
示例2: Client
# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import do_start [as 别名]
#.........这里部分代码省略.........
if resume_data:
tp['resume_data']=resume_data
elif uri.startswith('magnet:'):
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):
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):
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):
self._ses.stop_natpmp()
self._ses.stop_upnp()