def main(): parse_command_line() enable_pretty_logging() wsgi_app = wsgi.WSGIContainer(django.core.handlers.wsgi.WSGIHandler()) staticpath = [ _HERE + "/static/", _HERE + "/deb/", "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/", "/usr/local/lib/python2.7/dist-packages/django_admin_bootstrapped/static/", "/usr/local/lib/python2.7/dist-packages/bootstrap_markdown/static/", ] mapping = [ (r'/(favicon.ico)', web.StaticFileHandler, { 'path': _HERE + "/static" }), (r'/static/(.*)', MultiStaticFileHandler, { 'paths': staticpath }), (r'/deb/(.*)', MultiStaticFileHandler, { 'paths': staticpath }), ('.*', web.FallbackHandler, dict(fallback=wsgi_app)), ] tornado_app = web.Application(mapping, debug=True) server = httpserver.HTTPServer(tornado_app) server.listen(options.port) print "http://{}:{}".format(LOCALIP, options.port) try: ioloop.IOLoop.instance().start() except KeyboardInterrupt: ioloop.IOLoop.instance().stop() print "Finished"
def main(args): global server signal.signal(signal.SIGINT, stop) f = logging.Formatter('[%(asctime)s][%(name)s][%(levelname)s] %(message)s', '%Y-%b-%d %H:%M:%S') h = logging.StreamHandler(sys.stdout) h.setLevel(logging.INFO) h.setFormatter(f) for logger in {log.access_log, log.app_log, log.gen_log, app.logger}: logger.addHandler(h) logger.setLevel(logging.INFO) init_db( cfg.query('server', 'record_db', ret_default=os.path.join(os.getenv('HOME'), '.pysplit.sqlite'))) wsgi_container = wsgi.WSGIContainer(app) server = httpserver.HTTPServer(wsgi_container) server.listen(cfg.query('server', 'port', ret_default=5000)) ioloop.IOLoop.current().start()
def run(self): self.app.register_backend(self.srv_type, self.service_backend) if self.reg_srv: self.register_service() # setup shutdown handler for de-registration of service for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]: signal.signal(sig, self.shutdown_handler) up = urlparse(self.stg['service_endpoint']) dep_port = CONFIG.get('general', 'port') if dep_port != '': LOG.warn('DEPRECATED: parameter general: port in service manager config. ' 'Service port number (' + str(up.port) + ') is taken from the service manifest') if self.DEBUG: LOG.debug('Using WSGI reference implementation') httpd = make_server('', int(up.port), self.app) httpd.serve_forever() else: LOG.debug('Using tornado implementation') container = wsgi.WSGIContainer(self.app) http_server = httpserver.HTTPServer(container) http_server.listen(int(up.port)) ioloop.IOLoop.instance().start() LOG.info('Service Manager running on interfaces, running on port: ' + str(up.port))
def setUpClass(cls): cls.io_loop = ioloop.IOLoop() app = wsgi.WSGIContainer(TestingApp()) cls.http_server, cls.http_port = run_tornado_app( app, cls.io_loop, None, 'http', cls.http_host) app = wsgi.WSGIContainer(TestingApp()) cls.https_server, cls.https_port = run_tornado_app( app, cls.io_loop, cls.https_certs, 'https', cls.http_host) app = web.Application([(r'.*', ProxyHandler)]) cls.proxy_server, cls.proxy_port = run_tornado_app( app, cls.io_loop, None, 'http', cls.proxy_host) cls.server_thread = run_loop_in_thread(cls.io_loop)
def run_wsgi(wsgi_app, port): """Runs wsgi (Flask) app using tornado web server.""" container = wsgi.WSGIContainer(wsgi_app) app = tornado.web.Application([ (r".*", tornado.web.FallbackHandler, dict(fallback=container)), ]) app.listen(port) tornado.ioloop.IOLoop.instance().start()
def __init__(self, settings): metrics_handler = wsgi.WSGIContainer(make_wsgi_app()) handlers = [ (r'/webhooks/github', GithubWebhookHandler), (r'/metrics', metrics_handler) ] settings.update(dict( )) super().__init__(handlers, **settings)
def inner_run(): from django.conf import settings print 'Validating models...' self.validate(display_num_errors=True) print '\nDjango version %s, using settings %r' % (django.get_version(), settings.SETTINGS_MODULE) print 'Tornado Server is running at http://%s:%s/' % (addr, port) print 'Quit the server with %s.' % quit_command application = WSGIHandler() container = wsgi.WSGIContainer(application) http_server = httpserver.HTTPServer(container) http_server.listen(int(port), address=addr) ioloop.IOLoop.instance().start()
def run_wsgi_unix(wsgi_app, socket): """Runs wsgi (Flask) app using tornado unixsocket web server.""" container = wsgi.WSGIContainer(wsgi_app) app = tornado.web.Application([ (r".*", tornado.web.FallbackHandler, dict(fallback=container)), ]) http_server = tornado.httpserver.HTTPServer(app) unix_socket = tornado.netutil.bind_unix_socket(socket) http_server.add_socket(unix_socket) tornado.ioloop.IOLoop.instance().start()
def main(): import logging init_log(level=logging.DEBUG) class Test(HTTPResponse): def get(self): return "hello from Graily and tornado WSGIServer" app = Graily([(r'^.*$', Test)]) container = wsgi.WSGIContainer(app) http_server = httpserver.HTTPServer(container) http_server.listen(8888) tornado.ioloop.IOLoop.instance().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 runtornado(): from snow import wsgi, util from tornado import wsgi as twsgi from tornado import httpserver from tornado import ioloop from tornado import netutil container = twsgi.WSGIContainer(wsgi.app) sockets = netutil.bind_sockets(0, '') http_server = httpserver.HTTPServer(container) http_server.add_sockets(sockets) util.open_browser(sockets) ioloop.IOLoop.current().start()
def get_handler(self, *args, **kwargs): """Return Tornado application with Django WSGI handlers""" # Patch prepare method from Tornado's FallbackHandler FallbackHandler.prepare = patches.patch_prepare(FallbackHandler.prepare) django_app = wsgi.WSGIContainer(WSGIHandler()) handlers = ( URLSpec(r'/_', WelcomeHandler), URLSpec(r'.*', FallbackHandler, dict(fallback=django_app)), ) opts = { "debug": settings.DEBUG, "loglevel": settings.DEBUG and "debug" or "warn", } return Application(handlers, **opts)
def run(config): config.check_writeable_uid_directory(config.appdatahome) port = config['port'] or 8080 interface = config['interface'] app = CubicWebWSGIApplication(config) container = wsgi.WSGIContainer(app) http_server = httpserver.HTTPServer(container) http_server.listen(port, interface) repo = app.appli.repo try: LOGGER.info('starting http server on %s', config['base-url']) ioloop.IOLoop.instance().start() finally: repo.shutdown()
def main(): base_path = config.get_base_path() settings = { 'static_path': os.path.join(BASE_DIR, 'static'), 'static_url_prefix': base_path + '/static/', } wsgi_app = wsgi.WSGIContainer(app) handlers = [] if base_path: handlers += [(base_path, web.RedirectHandler, dict(url=base_path + '/'))] handlers += [(base_path + r'/.*', web.FallbackHandler, dict(fallback=wsgi_app))] tornado_app = web.Application(handlers, **settings) http_server = HTTPServer(tornado_app, ssl_options=get_ssl_option()) http_server.listen(config.get_port(), config.get_address()) print("Start success on port %d" % config.get_port()) IOLoop.current().start()
def prodserver(): setup_logging('prodserver') app = create_app(parse_options()) log_messages(app, OPTIONS['--port']) # Setup the application. container = wsgi.WSGIContainer(app) application = web.Application([ (r'/(favicon\.ico)', web.StaticFileHandler, dict(path=app.static_folder)), (r'/static/(.*)', web.StaticFileHandler, dict(path=app.static_folder)), (r'.*', web.FallbackHandler, dict(fallback=container)) ]) # From http://maxburstein.com/blog/django-static-files-heroku/ http_server = httpserver.HTTPServer(application) http_server.bind(OPTIONS['--port']) # Start the server. http_server.start(0) # Forks multiple sub-processes ioloop.IOLoop.instance().start()
def handle(self, port='', *args, **options): host = 'localhost' if port == '': port = '8080' sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0) print "Validating models..." self.validate(display_num_errors=True) print "\nDjango version %s, using settings %r" % ( django.get_version(), settings.SETTINGS_MODULE) print "Server is running at http://%s:%s/" % (host, port) application = get_wsgi_application() container = wsgi.WSGIContainer(application) http_server = httpserver.HTTPServer(container) http_server.listen(int(port), address=host) ioloop.IOLoop.instance().start()
def main(): base_path = config.get_base_path() settings = { "static_path": os.path.join(BASE_DIR, "static"), "static_url_prefix": base_path + "/static/", } wsgi_app = wsgi.WSGIContainer(app) handlers = [] if base_path: handlers += [(base_path, web.RedirectHandler, dict(url=base_path + "/"))] handlers += [(base_path + r"/.*", web.FallbackHandler, dict(fallback=wsgi_app))] tornado_app = web.Application(handlers, **settings) if config.get_v2_ext_tls(): http_server = HTTPServer(tornado_app, xheaders=True) else: http_server = HTTPServer(tornado_app, ssl_options=get_ssl_option()) http_server.listen(config.get_port(), config.get_address()) print("Start success on port %d" % config.get_port()) IOLoop.current().start()
def __init__(self, host='127.0.0.1', port=8080, **options): ## Generic Variables ## super(CustomTornado, self).__init__(host=host, port=port, **options) ## Extras ## self.handlers = [] # Web Socket Handlers # self.handlers.append((r'/status', WebsocketHandler, { 'ws_manager': self.options['ws_manager0'] })) self.handlers.append((r'/traps', WebsocketHandler, { 'ws_manager': self.options['ws_manager1'] })) # HTML Handler # self.handlers.append((r".*", web.FallbackHandler, { 'fallback': wsgi.WSGIContainer(self.options['web_app']) })) # Server Instances # self.tornado_app = web.Application(self.handlers) self.server = httpserver.HTTPServer(self.tornado_app) self.ioloop = ioloop.IOLoop.instance()
def execute(routes): # Servidor WSGI container = wsgi.WSGIContainer(routes) http_server = httpserver.HTTPServer(container) http_server.listen(PORT) ioloop.IOLoop.instance().start()
class ThreadMixin(object): executor = ThreadPoolExecutor(max_workers=4) class FallbackHandler(ThreadMixin, web.FallbackHandler): @run_on_executor def prepare(self): self.fallback(self.request) self._finished = True application = web.Application([ url(r'/media/(.*)', web.StaticFileHandler, {'path': settings.MEDIA_ROOT}), url(r'.*', FallbackHandler, {'fallback': wsgi.WSGIContainer(django_app)}) ], **APP_SETTINGS) def main(): if APP_SETTINGS['debug']: sys.stdout.write('Host: {}\n'.format(options.host)) sys.stdout.write('Port: {}\n\n'.format(options.port)) application.listen(options.port, options.host) try: IOLoop.instance().start() except KeyboardInterrupt: IOLoop.instance().stop() if __name__ == '__main__':
from tornado import wsgi, ioloop, httpserver, log from cprj.wsgi import application if __name__ == '__main__': container = wsgi.WSGIContainer(application) server = httpserver.HTTPServer(container) server.listen(8080, address='0.0.0.0') log.enable_pretty_logging() try: ioloop.IOLoop.current().start() except KeyboardInterrupt: ioloop.IOLoop.current().stop()
#!/usr/bin/env python import settings from tornado import wsgi from tornado import httpserver from tornado import ioloop import app http_server = httpserver.HTTPServer(wsgi.WSGIContainer(app.app)) http_server.listen(settings.WEBSERVER_PORT, address=settings.WEBSERVER_ADDRESS) ioloop.IOLoop.instance().start() # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
def DAVHandler(**settings): return wsgi.WSGIContainer(App(**settings))
import logging import signal from tornado import httpserver from tornado import ioloop from tornado import wsgi as t_wsgi logging.basicConfig(level='DEBUG') LOG = logging.getLogger(__name__) def shutdown(): print 'Goodbye cruel world...' ioloop.IOLoop.instance().stop() def sig_handler(sig, frame): ioloop.IOLoop.instance().add_callback(shutdown) if __name__ == '__main__': app = wsgi.get_app() container = t_wsgi.WSGIContainer(app) http_server = httpserver.HTTPServer(container) http_server.listen(8888) signal.signal(signal.SIGTERM, sig_handler) signal.signal(signal.SIGINT, sig_handler) i = ioloop.IOLoop.instance().start()
def _start_server(cls): cls.io_loop = ioloop.IOLoop() app = wsgi.WSGIContainer(TestingApp()) cls.server, cls.port = run_tornado_app(app, cls.io_loop, cls.certs, cls.scheme, cls.host) cls.server_thread = run_loop_in_thread(cls.io_loop)
# server.py = run the web server, using Tornado """ For running CatWiki using Tornado """ from tornado import wsgi from tornado import httpserver, ioloop import main import config if __name__ == "__main__": container = wsgi.WSGIContainer(main.app) http_server = httpserver.HTTPServer(container) http_server.listen(config.PORT) ioloop.IOLoop.instance().start() #end
# server.py """ For running app on Tornado server """ from tornado import wsgi from tornado import httpserver, ioloop from main import * if __name__ == "__main__": container = wsgi.WSGIContainer(app) http_server = httpserver.HTTPServer(container) http_server.listen(8300) ioloop.IOLoop.instance().start() #end