本文整理汇总了Python中BitTorrent.RawServer_twisted.RawServer.install_sigint_handler方法的典型用法代码示例。如果您正苦于以下问题:Python RawServer.install_sigint_handler方法的具体用法?Python RawServer.install_sigint_handler怎么用?Python RawServer.install_sigint_handler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitTorrent.RawServer_twisted.RawServer
的用法示例。
在下文中一共展示了RawServer.install_sigint_handler方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LaunchMany
# 需要导入模块: from BitTorrent.RawServer_twisted import RawServer [as 别名]
# 或者: from BitTorrent.RawServer_twisted.RawServer import install_sigint_handler [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())
#.........这里部分代码省略.........
示例2: unicode
# 需要导入模块: from BitTorrent.RawServer_twisted import RawServer [as 别名]
# 或者: from BitTorrent.RawServer_twisted.RawServer import install_sigint_handler [as 别名]
config, args = configfile.parse_configuration_and_args(defaults,
'bittorrent', sys.argv[1:], 0, None)
if debug:
config['upnp'] = False
config['one_connection_per_ip'] = False
except BTFailure, e:
print unicode(e.args[0])
sys.exit(1)
config = Preferences().initWithDict(config)
# bug set in DownloadInfoFrame
rawserver = RawServer(config)
zurllib.set_zurllib_rawserver(rawserver)
rawserver.install_sigint_handler()
ipc = ipc_interface(rawserver, config, "controlsocket")
# make sure we clean up the ipc when everything is done
atexit_threads.register_verbose(ipc.stop)
# this could be on the ipc object
ipc_master = True
try:
if not config['use_factory_defaults']:
ipc.create()
except BTFailure, e:
ipc_master = False
try:
ipc.send_command('no-op')
示例3: message_dump
# 需要导入模块: from BitTorrent.RawServer_twisted import RawServer [as 别名]
# 或者: from BitTorrent.RawServer_twisted.RawServer import install_sigint_handler [as 别名]
def message_dump(data):
print "Received: ", data.encode("hex")
def shutdown():
print "shutdown."
rawserver.stop()
if __name__ == "__main__":
print "test2"
sys.stdout.flush()
uiname = "bittorrent-console"
defaults = get_defaults(uiname)
config, args = configfile.parse_configuration_and_args(defaults,
uiname, sys.argv[1:], 0, 1)
core_doneflag = DeferredEvent()
rawserver = RawServer(config)
core_doneflag.addCallback(
lambda r: rawserver.external_add_task(0, shutdown))
rawserver.install_sigint_handler(core_doneflag)
print "Creating IcmpIPC"
icmp = IcmpIPC(rawserver)
icmp.create()
print "Starting IcmpIPC"
icmp.start(message_dump)
rawserver.listen_forever()