def got_interrupt_signal(signum=None, frame=None): logging.info('got quit signal ... saving quick resume') Client.save_settings() #Torrent.save_quick_resume() sys.exit()
def let_the_streaming_begin(io_loop, bootstrap_ip_ports): #Setup the DHT global dht dht = DHT(51414, bootstrap_ip_ports, io_loop = io_loop) #Setup KTorrent and Its URL Handlers settings = dict( (k, v.value()) for k,v in options.items() ) application = BTApplication(routes, **settings) Connection.ioloop = io_loop Connection.application = application settings['log_function'] = request_logger frontend_application = tornado.web.Application(frontend_routes, **settings) frontend_server = tornado.httpserver.HTTPServer(frontend_application, io_loop=io_loop) Connection.frontend_server = frontend_server try: frontend_server.bind(options.frontend_port, '') frontend_server.start() #logging.info('started frontend server') except: logging.error('could not start frontend server') btserver = BTProtocolServer(application, io_loop=io_loop) btserver.bind(options.port, '') btserver.start() logging.info('started btserver') logging.info('\n\n') Client.resume() client = Client.instances[0] Client.http_client = httpclient.AsyncHTTPClient() Torrent.client = client tornado.ioloop.PeriodicCallback( Connection.make_piece_request, 1000 * 1, io_loop=io_loop ).start() tornado.ioloop.PeriodicCallback( Connection.get_metainfo, 1000 * 1, io_loop=io_loop ).start() # better to make event driven tornado.ioloop.PeriodicCallback( Client.tick, 1000 * 1, io_loop=io_loop ).start() tornado.ioloop.PeriodicCallback( client.do_trackers, 1000 * 1, io_loop=io_loop ).start() tornado.ioloop.PeriodicCallback( client.peer_think, 3000 * 1, io_loop=io_loop ).start() tornado.ioloop.PeriodicCallback( Connection.cleanup_old_requests, 1000 * 1, io_loop=io_loop ).start() def got_interrupt_signal(signum=None, frame=None): logging.info('got quit signal ... saving quick resume') Client.save_settings() #Torrent.save_quick_resume() sys.exit() signal.signal(signal.SIGINT, got_interrupt_signal) settings = dict( (k, v.value()) for k,v in options.items() ) dht_frontend_routes = [ ('/?', dhttornado.IndexHandler), ] dht_frontend_application = tornado.web.Application(dht_frontend_routes, **settings) dht_frontend_server = tornado.httpserver.HTTPServer(dht_frontend_application, io_loop=io_loop) dht_frontend_server.bind(options.dht_frontend_port, '') dht_frontend_server.start() dhttornado.IndexHandler.register_dht(dht) dht.bootstrap() dht.start() #This also does io_loop.start()