Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use server-thread package #79

Merged
merged 4 commits into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies:
- flask-restx >=0.5.0
- pylibmc
- requests
- server-thread
- scooby
- pytest
- pytest-cov
Expand Down
21 changes: 18 additions & 3 deletions localtileserver/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
except ImportError:
DatasetReaderBase = None

from server_thread import ServerManager, launch_server

from localtileserver.configure import get_default_client_params
from localtileserver.server import ServerManager, launch_server
from localtileserver.manager import AppManager
from localtileserver.tileserver import get_building_docs, get_clean_filename, palette_valid_or_raise
from localtileserver.utilities import add_query_parameters, save_file_from_request

Expand Down Expand Up @@ -362,10 +364,15 @@ def __init__(
client_host: str = None,
client_prefix: str = None,
):
if DatasetReaderBase and isinstance(filename, DatasetReaderBase) and hasattr(filename, "name"):
if (
DatasetReaderBase
and isinstance(filename, DatasetReaderBase)
and hasattr(filename, "name")
):
filename = filename.name
super().__init__(filename)
self._key = launch_server(port, debug, host=host)
app = AppManager.get_or_create_app()
self._key = launch_server(app, port=port, debug=debug, host=host)
# Store actual port just in case
self._port = ServerManager.get_server(self._key).srv.port
client_host, client_port, client_prefix = get_default_client_params(
Expand All @@ -377,6 +384,14 @@ def __init__(
if BUILDING_DOCS and not client_host:
self._client_host = DEMO_REMOTE_TILE_SERVER

if not debug:
logging.getLogger("gdal").setLevel(logging.ERROR)
logging.getLogger("large_image").setLevel(logging.ERROR)
else:
logging.getLogger("gdal").setLevel(logging.DEBUG)
logging.getLogger("large_image").setLevel(logging.DEBUG)
logging.getLogger("large_image_source_gdal").setLevel(logging.DEBUG)
Comment on lines +387 to +393
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to double check how this actually behaves


def shutdown(self, force: bool = False):
if hasattr(self, "_key"):
ServerManager.shutdown_server(self._key, force=force)
Expand Down
16 changes: 16 additions & 0 deletions localtileserver/manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from localtileserver.tileserver import create_app


class AppManager:
_APP = None

def __init__(self):
raise NotImplementedError(
"The ServerManager class cannot be instantiated."
) # pragma: no cover

@staticmethod
def get_or_create_app():
if not AppManager._APP:
AppManager._APP = create_app()
return AppManager._APP
1 change: 1 addition & 0 deletions localtileserver/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, additional=None, ncol=3, text_width=80, sort=False):
"requests",
"werkzeug",
"click",
"server_thread",
"scooby",
] + large_image_core

Expand Down
147 changes: 0 additions & 147 deletions localtileserver/server.py

This file was deleted.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ large-image[memcached]>=1.13
large-image-source-gdal>=1.13
large-image-source-pil>=1.13
requests
server-thread
scooby
pytest
pytest-cov
Expand Down
1 change: 1 addition & 0 deletions requirements_win.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ large-image>=1.13
large-image-source-gdal>=1.13
large-image-source-pil>=1.13
requests
server-thread
scooby
pytest
pytest-cov
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"large-image>=1.13",
"large-image-source-gdal>=1.13",
"requests",
"server-thread",
"scooby",
],
extras_require={
Expand Down
2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import pytest
import requests
from server_thread import ServerDownError, ServerManager

from localtileserver.client import (
DEMO_REMOTE_TILE_SERVER,
RemoteTileClient,
TileClient,
get_or_create_tile_client,
)
from localtileserver.server import ServerDownError, ServerManager
from localtileserver.tileserver.utilities import get_clean_filename, get_tile_source

skip_pil_source = True
Expand Down