def run(self):
     logger.debug('Call waitress.serve in %r ...', self)
     wsgi_app = WSGIApp()
     server = waitress.create_server(wsgi_app, unix_socket=self.usock)
     wsgi_app.server = server
     self.server = server
     self.server_ready_event.set()
     server.run()
Пример #2
0
 def run(self, handler):
     from waitress import create_server
     if self.port:
         kw = dict(host=self.host, port=self.port)
     else:
         kw = dict(unix_socket=self.host)
     server = create_server(handler, threads=12, **kw)
     server.run()
Пример #3
0
 def serve(app, **kw):
     _quiet = kw.pop("_quiet", False)  # test shim
     _profile = kw.pop("_profile", False)  # test shim
     if not _quiet:  # pragma: no cover
         # idempotent if logging has already been set up
         logging.basicConfig()
     self._server = waitress.create_server(app, **kw)
     if not _quiet:  # pragma: no cover
         self._server.print_listen("Serving on http://{}:{}")
     if _profile:  # pragma: no cover
         waitress.profile("self._server.run()", globals(), locals(), (),
                          False)
     else:
         self._server.run()
Пример #4
0
    def block(self):
        # main-funksjonen avslutter når denne funksjonen returnerer
        log.info("run web interface")
        section = "webadmin"

        config = self.shared.config.config
        host = config(section, "host", "")
        port = config(section, "port", 8000)
        log.info("%s %s", host, port)

        # denne klassen tvinger asyncore til å stoppe.
        # denne må registreres i "map" når man ønsker å stoppe
        class _exit_asyncore:
            _counter = 0
            accepting = False

            def readable(self):
                if self._counter > 4:  # liten timeout før vi stopper
                    raise KeyboardInterrupt()
                else:
                    self._counter += 1
                return False

            def writable(self):
                return False

        try:
            # denne dict-en sendes helt ned til pollefunksjonene i asyncore og
            # kan av denne grunn benyttes til å stoppe webserver
            _map = {}

            def shutdown():
                # server.task_dispatcher.shutdown(timeout=1)
                _map["exit"] = _exit_asyncore()

            # gjør shutdown-funksjonen tilgjengelig for websidene i AdminIndex.py
            self.app.config["server.shutdown"] = shutdown

            # her startes webserveren, denne blokkerer til ctrl-c mottas
            server = waitress.create_server(self.app,
                                            host=host,
                                            port=port,
                                            map=_map)
            server.run()

        except KeyboardInterrupt:
            pass
# -*- coding: utf-8 -*-
"""
Copyright (C) 2017 tianyou pan <sherry0429 at SOAPython>
"""

import falcon
from service_delay import AuthMiddleware
from service_delay import ExampleError
from service_delay import ThingsResource
from waitress import create_server

# Configure your WSGI server to load "things.app" (app is a WSGI callable)
app = falcon.API(middleware=[AuthMiddleware()])

things = ThingsResource()
app.add_route('/{args}/things', things)

# If a responder ever raised an instance of StorageError, pass control to
# the given handler.
app.add_error_handler(ExampleError, ExampleError.handle)

if __name__ == '__main__':
    server = create_server(app, host="localhost", port=8080)
    server.run()
Пример #6
0
def create_server(application, ssl=None, **adj):
    """Create a wsgi server:

    .. code-block::

        >>> @asyncio.coroutine
        ... def application(environ, start_response):
        ...     pass
        >>> loop = asyncio.get_event_loop()
        >>> srv = create_server(application, loop=loop, port=2345)
        >>> srv.close()

    Then use ``srv.run()`` or ``loop.run_forever()``
    """
    if 'loop' in adj:
        loop = adj.pop('loop')
    else:
        loop = asyncio.get_event_loop()
    if 'ident' not in adj:
        adj['ident'] = 'aiowsgi'

    server = waitress.create_server(application, _start=False, **adj)

    adj = server.adj

    server.executor = None
    if not asyncio.iscoroutine(application) and \
       not asyncio.iscoroutinefunction(application):
        server.executor = ThreadPoolExecutor(max_workers=adj.threads)

    server.run = loop.run_forever
    server.loop = loop

    args = dict(app=[application],
                aioserver=None,
                adj=adj,
                loop=loop,
                server=server,
                server_name=server.server_name,
                effective_host=server.effective_host,
                effective_port=server.effective_port)
    proto = type(str('BoundedWSGIProtocol'), (WSGIProtocol, ), args)
    server.proto = proto

    if adj.unix_socket:
        utilities.cleanup_unix_socket(adj.unix_socket)
        f = loop.create_unix_server
    else:
        f = loop.create_server

    def done(future):
        result = future.result()
        server.aioserver = result

    task = asyncio.ensure_future(f(proto,
                                   sock=server.socket,
                                   backlog=adj.backlog,
                                   ssl=ssl),
                                 loop=loop)
    task.add_done_callback(done)
    return server
Пример #7
0
 def _configure_server(self):
     """Setup the server."""
     return waitress.create_server(self._app,
                                   host=self.host,
                                   port=self.port)