Exemplo n.º 1
0
class CodalabDaphneProcess(DaphneProcess):

    # have to set port in this hidden way so we can override it later (Daphne uses
    # fancy multiprocessing shared memory vars we have to work around
    _port = 36475

    def __init__(self,
                 host,
                 application,
                 kwargs=None,
                 setup=None,
                 teardown=None):
        super().__init__(host,
                         application,
                         kwargs=None,
                         setup=None,
                         teardown=None)

        # Move our port into shared memory
        self.port.value = self._port

    def run(self):
        """Overriding this _just_ for the port bit...!"""
        try:
            # Create the server class -- with our fancy multiprocessing variable (note
            # `self.port.value`)
            endpoints = build_endpoint_description_strings(
                host=self.host, port=self.port.value)
            self.server = Server(application=self.application,
                                 endpoints=endpoints,
                                 signal_handlers=False,
                                 **self.kwargs)
            # Set up a poller to look for the port
            reactor.callLater(0.1, self.resolve_port)
            # Run with setup/teardown
            self.setup()
            try:
                self.server.run()
            finally:
                self.teardown()
        except Exception as e:
            # Put the error on our queue so the parent gets it
            self.errors.put((e, traceback.format_exc()))
Exemplo n.º 2
0
def _run(addr, port, prod):
    # if True or prod:
    #    channel_layer = get_channel_layer()
    # else:
    #    channel_layer = channel_layers[DEFAULT_CHANNEL_LAYER]
    #    channel_layer.router.check_default(
    #        http_consumer=ViewConsumer(),
    #    )
    #    for _ in range(4):
    #        worker = WorkerThread(channel_layer)
    #        worker.daemon = True
    #        worker.start()
    try:
        from daphne.server import Server
        from daphne.endpoints import build_endpoint_description_strings
        from channels.routing import get_default_application

        django.setup()

        # application = django.core.handlers.wsgi.WSGIHandler()

        print(addr, port)
        endpoints = build_endpoint_description_strings(host=addr,
                                                       port=int(port))

        server = Server(
            # channel_layer=channel_layer,
            get_default_application(),
            endpoints=endpoints,
            # host=addr,
            # port=int(port),
            signal_handlers=False,
            action_logger=log_action,
            http_timeout=60,
        )
        server.run()
    except KeyboardInterrupt:
        return
Exemplo n.º 3
0
class DaphneProcess(ProcessSetup):
    def __init__(self, host, port_storage, is_ready, overridden_settings,
                 modified_settings, databases):

        self.host = host
        self.port_storage = port_storage
        self.is_ready = is_ready
        self.overridden_settings = overridden_settings
        self.modified_settings = modified_settings
        self.databases = databases
        super(DaphneProcess, self).__init__()
        self.daemon = True

    def run(self):

        try:
            self.common_setup()
            channel_layers = ChannelLayerManager()
            channel_layer = channel_layers.make_test_backend(
                DEFAULT_CHANNEL_LAYER)
            self.server = Server(
                channel_layer=channel_layer,
                endpoints=['tcp:interface=%s:port=0' % (self.host)],
                signal_handlers=False,
            )
            reactor.callLater(0.5, self.resolve_port)
            self.server.run()
        except Exception:
            self.is_ready.set()
            raise

    def resolve_port(self):

        port = self.server.listeners[0].result.getHost().port
        self.port_storage.value = port
        self.is_ready.set()
Exemplo n.º 4
0
class DaphneProcess(ProcessSetup):

    def __init__(self, host, port_storage, is_ready, overridden_settings,
                 modified_settings, databases):

        self.host = host
        self.port_storage = port_storage
        self.is_ready = is_ready
        self.overridden_settings = overridden_settings
        self.modified_settings = modified_settings
        self.databases = databases
        super(DaphneProcess, self).__init__()
        self.daemon = True

    def run(self):

        try:
            self.common_setup()
            channel_layers = ChannelLayerManager()
            channel_layer = channel_layers.make_test_backend(DEFAULT_CHANNEL_LAYER)
            self.server = Server(
                channel_layer=channel_layer,
                endpoints=['tcp:interface=%s:port=0' % (self.host)],
                signal_handlers=False,
            )
            reactor.callLater(0.5, self.resolve_port)
            self.server.run()
        except Exception:
            self.is_ready.set()
            raise

    def resolve_port(self):

        port = self.server.listeners[0].result.getHost().port
        self.port_storage.value = port
        self.is_ready.set()
Exemplo n.º 5
0
def main():
    os.environ.setdefault("DJANGO_SETTINGS_MODULE",
                          "stellaru.settings_release")
    django.setup()
    django.core.management.call_command("makemigrations")
    django.core.management.call_command("migrate")

    port = find_port()
    from stellaru import routing as stellaru_app
    application = StaticFilesWrapper(stellaru_app.application)
    endpoints = build_endpoint_description_strings(
        host=DEFAULT_HOST,
        port=port,
        unix_socket=None,
        file_descriptor=None,
    )
    server = Server(application=application,
                    endpoints=endpoints,
                    server_name='Stellaru')

    print('Starting Stellaru')
    thread = threading.Thread(target=open_browser, args=(port, ))
    thread.run()
    server.run()