def runloop(addr, port, xheaders, no_keep_alive, use_reloader): router = SockJSRouter(Connection, '/updates') handlers = [ (r'/', MainHandler), (r'/static/(.*)', tornado.web.StaticFileHandler, {'path': os.path.join(FILE_ROOT, 'static/')}), ] + router.urls tornado_app = tornado.web.Application(handlers) # start tornado web server in single-threaded mode # instead auto pre-fork mode with bind/start. http_server = httpserver.HTTPServer(tornado_app, xheaders=xheaders, no_keep_alive=no_keep_alive) http_server.listen(int(port), address=addr) main_loop = tornado.ioloop.IOLoop.instance() try: print "Runing on :{port}".format(port=port) main_loop.start() except KeyboardInterrupt: print "Stopped" sys.exit(0) if use_reloader: # Use tornado reload to handle IOLoop restarting. from tornado import autoreload autoreload.start() quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C' print quit_command + " to quit."
def run(self): http_server = HTTPServer(WSGIContainer(app)) http_server.listen(app_cfg[('SERVER', 'port')]) http_server.debug = app_cfg[('FLASK', 'debug_on')] ioloop = IOLoop.instance() autoreload.start(ioloop) ioloop.start()
def run(self, args): settings = self.get_settings() for name in map(basename, glob(join('controllers', '*.py'))): autoreload.watch(name) Module.load(self.get_controller_import_path(name)) from shrine.routes import make_application MESSAGE = "{} running at http://localhost:{}\n".format( settings.PRODUCT_NAME, settings.PORT, ) application = make_application() application.listen(settings.PORT) self.log.bold_green(MESSAGE) from shrine.log import logger logger.setLevel(logging.WARNING) try: autoreload.start() IOLoop.instance().start() except KeyboardInterrupt: self.log.bold_red_on_black("\rInterrupted by the User (Control-C)\n")
def runloop(addr, port, xheaders, no_keep_alive, use_reloader, daemonize=False): router = SockJSRouter(Connection, '/updates') handlers = router.urls + [ (r'/', TeaOrbitHandler), (r'/static/(.*)', tornado.web.StaticFileHandler, {'path': os.path.join(FILE_ROOT, 'static/')}), (r'/(?P<room_name>.*)', TeaOrbitHandler), ] tornado_app = tornado.web.Application(handlers) # start tornado web server in single-threaded mode # instead auto pre-fork mode with bind/start. http_server = httpserver.HTTPServer(tornado_app, xheaders=xheaders, no_keep_alive=no_keep_alive) http_server.listen(int(port), address=addr) main_loop = tornado.ioloop.IOLoop.instance() if use_reloader: # Use tornado reload to handle IOLoop restarting. from tornado import autoreload autoreload.start() for (path, dirs, files) in os.walk(os.path.join(FILE_ROOT)): for item in files: tornado.autoreload.watch(os.path.join(path, item)) try: print "*** listening on :{port}".format(port=port) if daemonize is True: log = open('tornado.log', 'a+') ctx = daemon.DaemonContext(stdout=log, stderr=log, working_directory='.') ctx.open() main_loop.start() except KeyboardInterrupt: print "Stopped" sys.exit(0)
def run(self, port, reload, host, logging, **kwargs): config = self._commandor_res if not config: self.error("You need specify --config\n") self.exit() configure_logging(logging) application = HTTPApplication(config) ioloop = tornado.ioloop.IOLoop.instance() application.configure_app(ioloop) self.http_server = httpserver.HTTPServer(application) self.http_server.listen(port, host) if reload: self.display("Autoreload enabled") autoreload.start(io_loop=ioloop, check_time=100) self.display("Server running on http://{0}:{1}".format(host, port)) # Init signals handler signal.signal(signal.SIGTERM, self.sig_handler) # This will also catch KeyboardInterrupt exception signal.signal(signal.SIGINT, self.sig_handler) ioloop.start()
def main(self): #settings passed to tornado app tornado_settings = { "template_path": settings.template_path, "static_path": settings.static_path, "cookie_secret": settings.cookie_secret, "login_url": settings.login_url, } #init a logger self.init_logging(settings.log) #routes routes = self.init_routes() self._application = web.Application(routes,**tornado_settings) http_server = httpserver.HTTPServer(self._application) http_server.listen(settings.port) Log.info("Ready and listening") ioloop = tornado.ioloop.IOLoop().instance() autoreload.start(ioloop) try: ioloop.start() except KeyboardInterrupt: pass
def start_server(address: str = None, port: int = None, check_time: int = 500, **kwargs: Any) -> module.HTTPServer: """Start web server on ``address:port``. Use wrapper function :func:`start` instead. :arg str address: address of the server [default: localhost]. :arg int port: tcp port of the server [default: 8888]. :arg int check_time: millisecondes to wait until reload browser when autoreload is enabled [default: 500]. """ # Add application's static files directory from wdom.document import get_document add_static_path('_static', STATIC_DIR) doc = get_document() if os.path.exists(doc.tempdir): add_static_path('tmp', doc.tempdir, no_watch=True) if doc._autoreload or config.autoreload or config.debug: autoreload.start(check_time=check_time) global _server _server = module.start_server(address=address, port=port, **kwargs) logger.info('Start server on {0}:{1:d}'.format(server_config['address'], server_config['port'])) # start messaging loop asyncio.ensure_future(_message_loop()) if config.open_browser: open_browser( 'http://{}:{}/'.format(server_config['address'], server_config['port']), config.browser) return _server
def run(self, reload, logging, **kwargs): config = self._commandor_res if not config: self.error("You need specify --config\n") self.exit() configure_logging(logging) self.application = AggregatorApplication(config) ioloop = tornado.ioloop.IOLoop.instance() self.application.configure_app(ioloop) if reload: self.display("Autoreload enabled") autoreload.start(io_loop=ioloop, check_time=100) # Init signals handler signal.signal(signal.SIGTERM, self.sig_handler) # This will also catch KeyboardInterrupt exception signal.signal(signal.SIGINT, self.sig_handler) ioloop.start()
def run(): router = SockJSRouter(connections.PhotoStream, settings.SOCKET_STREAMER_URL) handlers = router.urls runtime_vars = dict() runtime_vars["last_obj_count"] = None runtime_vars.update(MultiuploaderImage.objects.aggregate(last_upload=Max('upload_date'))) def db_periodic_check(*a, **kw): obj_count = MultiuploaderImage.objects.count() if obj_count != runtime_vars["last_obj_count"]: runtime_vars["last_obj_count"] = obj_count if not runtime_vars["last_upload"] is None: objs = MultiuploaderImage.objects.filter(upload_date__gt=runtime_vars["last_upload"]) runtime_vars.update(MultiuploaderImage.objects.aggregate(last_upload=Max('upload_date'))) for obj in objs: for user in connections.PhotoStream.connected_users: user.notify_new_entry(obj) app = web.Application(handlers) app.listen(int(settings.SOCKET_STREAMER_PORT), "0.0.0.0") ioloop.PeriodicCallback(db_periodic_check, 1000).start() autoreload.start(ioloop.IOLoop.instance()) print "socket streamer is (re)started" try: ioloop.IOLoop.instance().start() except KeyboardInterrupt: return
def main(): server = make_app() server.listen(options.port, options.address) print('listening on ' + str(options.address) + ':' + str(options.port)) autoreload.start() autoreload.watch(config_path.web) IOLoop.instance().start()
def start_thememapper(): global nav global mapper #initialize the necessary classes mapper = Mapper(get_settings()) nav = Navigation() # Adds the ability to set config file and port through commandline p = optparse.OptionParser() p.add_option('--port', '-p', default=mapper.port,help='port thememapper should run at') p.add_option('--diazo', '-d', default=False,action="store_true",dest="diazo",help='force diazo server to run') p.add_option('--diazo_port', '-f', default=mapper.diazo_port,help='port diazo should run at') options = p.parse_args()[0] mapper.port = options.port mapper.diazo_port = options.diazo_port #start thememapper print "Starting thememapper on http://0.0.0.0:" + mapper.port HTTPServer(WSGIContainer(app)).listen(mapper.port) if options.diazo or mapper.diazo_run == 'True': try: from thememapper.diazo import server print "Starting diazo on http://0.0.0.0:" + mapper.diazo_port HTTPServer(server.get_application(mapper)).listen(mapper.diazo_port) except ImportError: print "You will need to install thememapper.diazo before being able to use this function." ioloop = IOLoop.instance() autoreload.watch(os.path.join(os.path.dirname(__file__), 'settings.properties')) autoreload.add_reload_hook(reload) autoreload.start(ioloop) ioloop.start()
def run_webui(): http_server = HTTPServer(WSGIContainer(app)) http_server.listen(5000) # 对应flask的端口 from tornado import autoreload autoreload.start() IOLoop.instance().current().start()
def startTornado(): global http_server http_server = HTTPServer(WSGIContainer(create_app("settings.DevelopmentConfig"))) http_server.listen(80) ioloop = IOLoop.instance() autoreload.start(ioloop) ioloop.start()
def main(): parse_command_line() http_server = tornado.httpserver.HTTPServer(Application()) http_server.listen(options.port) ioloop = tornado.ioloop.IOLoop().instance() autoreload.start(ioloop) ioloop.start()
def main() -> None: '''Runs server''' # Parse options define('production', default=False, help='run in production mode', type=bool) options.parse_command_line() # Set server name pname = settings.process_name if settings.process_name else None if pname: setproctitle(pname) # Register IRC server server = IRCServer(settings=ircdsettings) for address, port in ircdsettings['listen']: server.listen(port, address=address) # Start profiling if settings.profiling: import yappi yappi.start() # Setup autoreload autoreload.start() # Run application IOLoop.instance().start()
def main() -> None: '''Runs server''' # Parse options define('production', default = False, help = 'run in production mode', type = bool) options.parse_command_line() # Set server name pname = settings.process_name if settings.process_name else None if pname: setproctitle(pname) # Register IRC server server = IRCServer(settings = ircdsettings) for address, port in ircdsettings['listen']: server.listen(port, address = address) # Start profiling if settings.profiling: import yappi yappi.start() # Setup autoreload autoreload.start() # Run application IOLoop.instance().start()
def run(self, host=None, port=None, debug=None, **options): from tornado.wsgi import WSGIContainer from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop import tornado if host is None: host = "127.0.0.1" if port is None: port = 5000 if debug is not None: self.debug = bool(debug) hostname = host port = port application = self use_reloader = self.debug use_debugger = self.debug if use_debugger: from werkzeug.debug import DebuggedApplication application = DebuggedApplication(application, True) container = WSGIContainer(application) self.http_server = HTTPServer(container) sockets = tornado.netutil.bind_sockets(port, hostname) tornado.process.fork_processes(0) # self.http_server.listen(port, hostname) self.http_server.add_sockets(sockets) if use_reloader: from tornado import autoreload autoreload.start() self.ioloop = IOLoop.current() self.ioloop.start()
def start(): app = Application() app.listen(43802) if os.environ.get('TORNADO_ENV', 'dev') == 'dev': autoreload.start() ioloop.IOLoop.current().start()
def main(): print("starting service") app = mail_http.mail_handlers() server = httpserver.HTTPServer(app) server.bind(8888) server.start(0) # Forks multiple sub-processes autoreload.start() IOLoop.current().start()
def enable_autoreload(self, watch_dirs=list()): for current_dir in watch_dirs: if not os.path.isdir(current_dir): continue for (path, dirs, files) in os.walk(current_dir): for item in files: autoreload.watch(os.path.join(path, item)) autoreload.start(self.__io_loop)
def startTornado(): global http_server http_server = HTTPServer( WSGIContainer(create_app("settings.DevelopmentConfig"))) http_server.listen(80) ioloop = IOLoop.instance() autoreload.start(ioloop) ioloop.start()
def new_application(): mappings = [('/res/(.*)', StaticFileHandler, { 'path': os.path.join(os.path.dirname(__file__), 'res') })] + MAPPINGS application = Application( mappings, cookie_secret="__theEOCDB_secretEncryptionString__") autoreload.add_reload_hook('ocdb/core/res/validation_config.json') autoreload.start() return application
def start(self): self.sockets = tornado.netutil.bind_sockets( *self.naumanni_app.config.listen) # debugなのでautoreloadする AsyncIOMainLoop().install() from tornado import autoreload autoreload.start() self._run_server(None)
def serve(options): """Serves the server""" config = options.config app = Application(config) http_server = tornado.httpserver.HTTPServer(app) http_server.listen(WEB_PORT) ioloop = tornado.ioloop.IOLoop.instance() autoreload.start(ioloop) ioloop.start()
def app_autoreload(app, timeout): """Set application autoreload. This option available only on Debug mod.""" if app.config.get_settings_item('run', 'debug'): from tornado import autoreload autoreload.start( io_loop=tornado.ioloop.IOLoop.current(), check_time=2 )
def main(): options.parse_command_line() http_server = httpserver.HTTPServer(Application()) http_server.listen(options.port) print("Listening on port: " + str(options.port)) autoreload.start() ioloop.IOLoop.instance().start()
def main(): options.parse_command_line() app = web.Application([ (r'/(.*?)', CacheHandler) ]) app.listen(int(getconfig('server_port'))) autoreload.start() ioloop.IOLoop.instance().start()
def start_diazo_server(settings): app = get_application(settings) if app is not False: print "Starting diazo on http://0.0.0.0:" + settings['diazo_port'] HTTPServer(app).listen(settings['diazo_port']) ioloop = IOLoop.instance() autoreload.add_reload_hook(reload) autoreload.start(ioloop) ioloop.start()
def main(): define("port", default=8888, help="run on the given port", type=int) autoreload.start() parse_command_line() app.listen(options.port) IOLoop.current().start()
def main(): server.git = git.bake(_cwd=server.settings.repo) if options.listen_localhost_only: server.listen(options.port, 'localhost') else: server.listen(options.port) autoreload.start() autoreload.watch(config_path.web) IOLoop.instance().start()
def __init__(self, handler_class, **settings): self.handler_class = handler_class self.settings = settings if self.settings.get('debug'): self.settings.setdefault('autoreload', True) # Automatically reload modified modules if self.settings.get('autoreload'): from tornado import autoreload autoreload.start()
def handle(self, *args, **options): logging.info("Start tornado application on %s port %s" % (DEFAULT_IP, DEFAULT_PORT)) server = HTTPServer(request_callback=App()) server.listen(port=DEFAULT_PORT, address=DEFAULT_IP) io_loop = IOLoop.instance() if hasattr(settings, 'TORNADO_DEBUG'): autoreload.start(io_loop) io_loop.start()
def main(): if settings.DEBUG: log.info('starting Tornado autoreload') autoreload.start() log.info('*** main() ***') try: IOLoop.instance().run_sync(main_loop) except KeyboardInterrupt: log.info('^C, quitting')
def main(): from tornado.httpserver import HTTPServer tornado.options.parse_command_line() http_server = tornado.httpserver.HTTPServer(Application()) real_port = options.port - options.port_offset http_server.listen(real_port) print('Listening at port %s' % real_port) ioloop = tornado.ioloop.IOLoop.instance() autoreload.start(ioloop) ioloop.start()
def main(): from tornado.httpserver import HTTPServer tornado.options.parse_command_line() http_server = tornado.httpserver.HTTPServer(Application()) real_port = 3000 http_server.listen(real_port) print('Listening at port %s' % real_port) ioloop = tornado.ioloop.IOLoop.instance() autoreload.start(ioloop) ioloop.start()
def run(port=2221, bind="0.0.0.0"): from libs.ftpserver import FTPServer from tornado.ioloop import IOLoop from tornado import autoreload autoreload.start() from tornado.log import enable_pretty_logging enable_pretty_logging() server = FTPServer(connect_cls=XunleiFTPConnection, debug=True) server.listen(port, bind) print 'listening on %s:%s' % (bind, port) IOLoop.instance().start()
def __init__(self, config): self.config = config autoreload.start() logger_info('Application reloaded') rest_path = r'/api/001/' handlers = [('/?', DemoHandler), (rest_path + r'predict/?', PredictionHandler.make_api())] settings = { 'static_path': config['static_path'], 'template_path': config['template_path'] } tornado.web.Application.__init__(self, handlers, **settings)
def serve(self): with self: # Automatically reload modified modules (from Tornado's # Application.__init__). This code must be done here *after* # daemonize, because it instanciates ioloop for current PID. if self.app.webapp.settings.get('autoreload'): autoreload.start() logger.info("Serving temboardui on https://%s:%d", self.app.config.temboard.address, self.app.config.temboard.port) tornado.ioloop.IOLoop.instance().start()
def main(): tornado.options.parse_command_line() http_server = tornado.httpserver.HTTPServer(Application()) http_server.listen(options.port) from tornado import autoreload autoreload.watch("templates/home.html") autoreload.watch("templates/users.html") autoreload.watch("templates/changepassword.html") autoreload.watch("templates/register.html") autoreload.watch("templates/register_stepone.html") autoreload.start() tornado.ioloop.IOLoop.instance().start()
def __init__(self, config): self.config = config autoreload.start() logger_info('Application reloaded') rest_path = r'/api/001/' handlers = [('/?', DemoHandler), (rest_path + r'predict/?', PredictionHandler.make_api()) ] settings = { 'static_path': config['static_path'] , 'template_path': config['template_path'] } tornado.web.Application.__init__(self, handlers, **settings)
def run(self): """CircleCoreを起動する.""" for worker in self.workers: worker.initialize() if self.debug: from tornado import autoreload autoreload.start() try: self.hub.run() finally: for worker in self.workers: worker.finalize()
def __init__(self, handlers=None, default_host=None, transforms=None, **settings): if transforms is None: self.transforms = [] if settings.get("compress_response") or settings.get("gzip"): self.transforms.append(GZipContentEncoding) else: self.transforms = transforms self.default_host = default_host self.settings = settings self.ui_modules = { 'linkify': _linkify, 'xsrf_form_html': _xsrf_form_html, 'Template': TemplateModule, } self.ui_methods = {} self._load_ui_modules(settings.get("ui_modules", {})) self._load_ui_methods(settings.get("ui_methods", {})) if self.settings.get("static_path"): path = self.settings["static_path"] handlers = list(handlers or []) static_url_prefix = settings.get("static_url_prefix", "/static/") static_handler_class = settings.get("static_handler_class", StaticFileHandler) static_handler_args = settings.get("static_handler_args", {}) static_handler_args['path'] = path for pattern in [ re.escape(static_url_prefix) + r"(.*)", r"/(favicon\.ico)", r"/(robots\.txt)" ]: handlers.insert( 0, (pattern, static_handler_class, static_handler_args)) if self.settings.get('debug'): self.settings.setdefault('autoreload', True) self.settings.setdefault('compiled_template_cache', False) self.settings.setdefault('static_hash_cache', False) self.settings.setdefault('serve_traceback', True) self.wildcard_router = _ApplicationRouter(self, handlers) self.default_router = _ApplicationRouter( self, [Rule(AnyMatches(), self.wildcard_router)]) # Automatically reload modified modules if self.settings.get('autoreload'): from tornado import autoreload autoreload.start()
def run(self, host=None, port=None, debug=None, **options): import tornado.wsgi import tornado.ioloop import tornado.httpserver import tornado.web if host is None: host = '127.0.0.1' if port is None: server_name = self.config['SERVER_NAME'] if server_name and ':' in server_name: port = int(server_name.rsplit(':', 1)[1]) else: port = 5000 if debug is not None: self.debug = bool(debug) hostname = host port = port application = self use_reloader = self.debug use_debugger = self.debug # 使用werkzeug可以解决uWSGI下debug flask的问题 # https://codeseekah.com/2012/10/28/dubugging-flask-applications-under-uwsgi/ if use_debugger: from werkzeug.debug import DebuggedApplication application = DebuggedApplication(application, True) try: from .webdav import dav_app except ImportError as e: logger.warning('WebDav interface not enabled: %r', e) dav_app = None if dav_app: from werkzeug.wsgi import DispatcherMiddleware application = DispatcherMiddleware(application, { '/dav': dav_app }) container = tornado.wsgi.WSGIContainer(application) self.http_server = tornado.httpserver.HTTPServer(container) self.http_server.listen(port, hostname) if use_reloader: from tornado import autoreload autoreload.start() self.logger.info('webui running on %s:%s', hostname, port) self.ioloop = tornado.ioloop.IOLoop.current() self.ioloop.start()
def start_server(options): os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pydash.django_settings") import pydash.django_settings pydash.django_settings.TEMPLATE_DIRS = (options['template_path'],) app = web.Application([ (r"/static/(.*)", web.StaticFileHandler, {"path":options['static_path']}), ('.*', web.FallbackHandler, dict(fallback=wsgi.WSGIContainer(django_wsgi.WSGIHandler()))), ]) server = httpserver.HTTPServer(app) server.listen(options['port']) loop=ioloop.IOLoop.instance() autoreload.start(loop) loop.start()
def run(self, host=None, port=None, debug=None, **options): import tornado.wsgi import tornado.ioloop import tornado.httpserver import tornado.web if host is None: host = "127.0.0.1" if port is None: server_name = self.config["SERVER_NAME"] if server_name and ":" in server_name: port = int(server_name.rsplit(":", 1)[1]) else: port = 5000 if debug is not None: self.debug = bool(debug) hostname = host port = port application = self use_reloader = self.debug use_debugger = self.debug if use_debugger: from werkzeug.debug import DebuggedApplication application = DebuggedApplication(application, True) try: from .webdav import dav_app except ImportError as e: logger.warning("WebDav interface not enabled: %r", e) dav_app = None if dav_app: from werkzeug.wsgi import DispatcherMiddleware application = DispatcherMiddleware(application, {"/dav": dav_app}) container = tornado.wsgi.WSGIContainer(application) self.http_server = tornado.httpserver.HTTPServer(container) self.http_server.listen(port, hostname) if use_reloader: from tornado import autoreload autoreload.start() self.logger.info("webui running on %s:%s", hostname, port) self.ioloop = tornado.ioloop.IOLoop.current() self.ioloop.start()
def main(): tornado.options.parse_command_line() app = Application() app.listen(options.port) main_loop= tornado.ioloop.IOLoop.instance() #tornado.ioloop.PeriodicCallback(test2, 5000).start() tornado.ioloop.PeriodicCallback(updateEvents, PERIOD).start() #main_loop.add_timeout(datetime.timedelta(seconds=5), test) #remove in prod autoreload.start(main_loop) dirstowatch=['/vagrant/smartevents/static','/vagrant/smartevents/templates'] for directory in dirstowatch: for dir, _, files in os.walk(directory): [autoreload.watch(dir + '/' +f) for f in files if not f.startswith('.')] main_loop.start()
def start(): # initialize the tornado server http_server = httpserver.HTTPServer( wsgi.WSGIContainer(app) ) http_server.listen(app_port) io_loop = ioloop.IOLoop.instance() autoreload.start(io_loop) # add the io_loop to the bokeh server run_bokeh_server(io_loop) print('Starting the server on http://{}:{}/'.format(host, app_port)) # run the bokeh server io_loop.start()
def web_server(wiki, port, debug=False): def kill_handler(signal_number, stack_frame): logger.info('\nStopping wiki') sys.exit(1) signal.signal(signal.SIGINT, kill_handler) logger.info('Starting wiki on port {}. Ctrl+C will kill it.'.format(port)) HTTPServer(WSGIContainer(wiki)).listen(port) ioloop = IOLoop.instance() if debug: autoreload.start(ioloop) ioloop.start()
def main(name, urls_in, tornado_port=8080, mongo=('localhost', 27017, None), secret='You really REALLY should set this!', **kwargs): usage = "Usage: %prog (server [port]|shell) [options]" parser = OptionParser(usage=usage) parser.add_option("-r","--reload",action="store_true",dest="use_reloader", help="Tells Bongo to use the auto-reloader.") (options, args) = parser.parse_args() if len(args) < 1 or args[0] not in ['server','shell']: parser.error("must supply either server or shell argument") connect(name.replace(' ', '_'), mongo[0]) settings.__dict__.update(kwargs) if args[0] == 'server': if len(args) > 1: tornado_port = int(args[1]) urls = [] for v in urls_in: if type(v) == type and issubclass(v, web.RequestHandler): k = v.url else: k, v = v if issubclass(v, SerialHandler): urls.append(('^/'+k+'(?:.xml|.json|)$', v)) else: urls.append(('^/'+k+'$', v)) app_kwargs = {'cookie_secret':secret} if hasattr(settings, 'static'): app_kwargs['static_path'] = settings.static application = web.Application(urls, **app_kwargs) http_server = httpserver.HTTPServer(application) http_server.listen(tornado_port) if options.use_reloader: settings.__dict__.update({'USE_RELOADER':options.use_reloader}) from tornado import autoreload autoreload.start() print '\nReloading Bongo\n' print 'Running %s server on port %i' % (name, tornado_port) ioloop.IOLoop.instance().start() elif args[0] == 'shell': try: from IPython.Shell import IPShellEmbed IPShellEmbed()(header='%s (IPython Shell)' % name) except: import code code.interact('%s (Shell)' % name)
def run(self, workers_module="nsqworker.workers", debug=False, **kw): worker = load_worker(self._topic, self._channel, workers_module) logger.debug("Starting worker: %s" % worker) topic = "%s%s" % (self._topic_prefix, self._topic) legacy = False try: from nsq import LegacyReader except ImportError: legacy = True if not legacy: # nsq 0.5+ for name, handler in iteritems(worker.handlers): r = nsq.Reader( topic, "%s_%s" % (self._channel, name[0:-len("_handler")]), message_handler=handler, lookupd_http_addresses=self._nsqlookupd_http_addresses, **kw) # override default preprocess and validate method with worker's # method r.validate_message = worker.validate_message r.preprocess_message = worker.preprocess_message else: # nsq 0.4 r = nsq.Reader( all_tasks=worker.handlers, topic=topic, channel=self._channel, lookupd_http_addresses=self._nsqlookupd_http_addresses, **kw) r.validate_message = worker.validate_message r.preprocess_message = worker.preprocess_message if debug: autoreload.start() nsq.run()