本文整理匯總了Python中BitTorrent.RawServer_twisted.RawServer.stop方法的典型用法代碼示例。如果您正苦於以下問題:Python RawServer.stop方法的具體用法?Python RawServer.stop怎麽用?Python RawServer.stop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類BitTorrent.RawServer_twisted.RawServer
的用法示例。
在下文中一共展示了RawServer.stop方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: print_list
# 需要導入模塊: from BitTorrent.RawServer_twisted import RawServer [as 別名]
# 或者: from BitTorrent.RawServer_twisted.RawServer import stop [as 別名]
print_list(list)
df = nattraverser.register_port(internal_port, internal_port, "TCP")
external_port = like_yield(df)
print "Mapped:", external_port
list = like_yield(nattraverser.list_ports())
print_list(list)
# synchronous
nattraverser.unregister_port(external_port, "TCP")
list = like_yield(nattraverser.list_ports())
print_list(list)
if __name__ == "__main__":
rawserver = RawServer({'upnp': True})
nattraverser = NatTraverser(rawserver)
port = 6881
if len(sys.argv) > 1:
port = int(sys.argv[1])
df = run_tests(port)
def error(f):
print f
df.addErrback(error)
df.addBoth(lambda r: rawserver.stop())
rawserver.listen_forever()
示例2: LaunchMany
# 需要導入模塊: from BitTorrent.RawServer_twisted import RawServer [as 別名]
# 或者: from BitTorrent.RawServer_twisted.RawServer import stop [as 別名]
class LaunchMany(object):
def __init__(self, config, display, configfile_key):
"""Starts torrents for all .torrent files in a directory tree.
All errors are logged using Python logging to 'configfile_key' logger.
@param config: Preferences object storing config.
@param display: output function for stats.
"""
# 4.4.x version of LaunchMany output exceptions to a displayer.
# This version only outputs stats to the displayer. We do not use
# the logger to output stats so that a caller-provided object
# can provide stats formatting as opposed to using the
# logger Formatter, which is specific to exceptions, warnings, and
# info messages.
self.logger = logging.getLogger(configfile_key)
try:
self.multitorrent = None
self.rawserver = None
self.config = config
self.configfile_key = configfile_key
self.display = display
self.torrent_dir = config['torrent_dir']
# Ex: torrent_cache = infohash -> (path,metainfo)
self.torrent_cache = {}
# maps path -> [(modification time, size), infohash]
self.file_cache = {}
# used as set containing paths of files that do not have separate
# entries in torrent_cache either because torrent_cache already
# contains the torrent or because the torrent file is corrupt.
self.blocked_files = {}
#self.torrent_list = []
#self.downloads = {}
self.hashcheck_queue = []
#self.hashcheck_store = {}
self.hashcheck_current = None
self.core_doneflag = DeferredEvent()
self.rawserver = RawServer(self.config)
try:
# set up shut-down procedure before we begin doing things that
# can throw exceptions.
def shutdown():
self.logger.critical(_("shutting down"))
for t in self.multitorrent.get_torrents():
self.logger.info(_('dropped "%s"') %
self.torrent_cache[t.infohash][0])
if self.multitorrent:
df = self.multitorrent.shutdown()
set_flag = lambda *a : self.rawserver.stop()
df.addCallbacks(set_flag, set_flag)
else:
self.rawserver.stop()
# It is safe to addCallback here, because there is only one thread,
# but even if the code were multi-threaded, core_doneflag has not
# been passed to anyone. There is no chance of a race condition
# between the DeferredEvent's callback and addCallback.
self.core_doneflag.addCallback(
lambda r: self.rawserver.external_add_task(0, shutdown))
self.rawserver.install_sigint_handler(self.core_doneflag)
data_dir = config['data_dir']
self.multitorrent = MultiTorrent(config, self.rawserver, data_dir,
resume_from_torrent_config=False)
self.rawserver.add_task(0, self.scan)
self.rawserver.add_task(0.5, self.periodic_check_hashcheck_queue)
self.rawserver.add_task(self.config['display_interval'],
self.periodic_stats)
try:
import signal
def handler(signum, frame):
self.rawserver.external_add_task(0, self.read_config)
signal.signal(signal.SIGHUP, handler)
except Exception, e:
self.logger.error(_("Could not set signal handler: ") +
str_exc(e))
self.rawserver.add_task(0,self.core_doneflag.set())
except UserFailure, e:
self.logger.error(str_exc(e))
self.rawserver.add_task(0,self.core_doneflag.set())
except:
data = StringIO()
print_exc(file = data)
self.logger.error(data.getvalue())
self.rawserver.add_task(0,self.core_doneflag.set())
#.........這裏部分代碼省略.........
示例3: xrange
# 需要導入模塊: from BitTorrent.RawServer_twisted import RawServer [as 別名]
# 或者: from BitTorrent.RawServer_twisted.RawServer import stop [as 別名]
for i in xrange(NUM_PEERS):
multitorrent = create_multitorrent(config, rawserver, i)
multitorrent._id = i
ms.append(multitorrent)
for t in args:
p = multitorrent.config['data_dir']
p = os.path.join(p, '%s.dat' % i)
multitorrent.create_torrent_non_suck(efs2(t), efs2(p))
task.LoopingCall(print_status, ms).start(5)
rawserver.listen_forever()
except:
for m in ms:
ddir = m.config['data_dir']
if os.path.exists(ddir):
shutil.rmtree(ddir)
# oops, we failed.
# one message for the log w/ exception info
global_logger.exception("BitTorrent core initialization failed!")
# one message for the user w/o info
global_logger.critical("BitTorrent core initialization failed!")
core_doneflag.set()
rawserver.stop()
raise