Skip to content

Commit

Permalink
Remove multiprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
bartfeenstra committed Feb 24, 2024
1 parent 5a9bf6b commit fbe2700
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 553 deletions.
2 changes: 0 additions & 2 deletions betty/_package/pyinstaller/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
from multiprocessing import freeze_support

from betty.app import App
from betty.asyncio import sync
Expand All @@ -12,7 +11,6 @@ async def main() -> None:
"""
Launch Betty for PyInstaller builds.
"""
freeze_support()
async with App() as app:
qapp = BettyApplication([sys.argv[0]], app=app)
window = WelcomeWindow(app)
Expand Down
28 changes: 0 additions & 28 deletions betty/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from __future__ import annotations

import operator
import os as stdos
import weakref
from collections.abc import Callable
from contextlib import suppress
from functools import reduce
from graphlib import CycleError, TopologicalSorter
Expand Down Expand Up @@ -157,21 +155,6 @@ def _unreduce(cls, dumped_app_configuration: VoidableDump, project: Project) ->
project,
)

def __reduce__(self) -> tuple[
Callable[[VoidableDump, Project], Self],
tuple[
VoidableDump,
Project,
],
]:
return (
App._unreduce,
(
self._configuration.dump(),
self._project,
),
)

async def __aenter__(self) -> Self:
await self.start()
return self
Expand Down Expand Up @@ -341,17 +324,6 @@ def renderer(self) -> Renderer:
def renderer(self) -> None:
self._renderer = None

@property
def concurrency(self) -> int:
with suppress(KeyError):
return int(stdos.environ['BETTY_CONCURRENCY'])
# Assume that any machine that runs Betty has at least two CPU cores.
return stdos.cpu_count() or 2

@property
def async_concurrency(self) -> int:
return self.concurrency ** 2

@property
def http_client(self) -> aiohttp.ClientSession:
if not self._http_client:
Expand Down
7 changes: 2 additions & 5 deletions betty/assets/betty.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Betty VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-02-17 18:26+0000\n"
"POT-Creation-Date: 2024-02-24 13:08+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -410,10 +410,7 @@ msgstr ""
msgid "Generate site"
msgstr ""

msgid "Generated pages for {count} {entity_type} in {locale}."
msgstr ""

msgid "Generated the listing page for {entity_type} in {locale}."
msgid "Generated {completed_job_count} out of {total_job_count} items ({completed_job_percentage}%)."
msgstr ""

msgid "Generating JSON Schema..."
Expand Down
11 changes: 5 additions & 6 deletions betty/assets/locale/de-DE/betty.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Betty VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-02-17 18:26+0000\n"
"POT-Creation-Date: 2024-02-24 13:08+0000\n"
"PO-Revision-Date: 2024-02-08 13:24+0000\n"
"Last-Translator: Bart Feenstra <bart@bartfeenstra.com>\n"
"Language: de\n"
Expand Down Expand Up @@ -574,11 +574,10 @@ msgstr "Seiten zur Auflistung von Entitäten generieren"
msgid "Generate site"
msgstr "Seite erzeugen"

msgid "Generated pages for {count} {entity_type} in {locale}."
msgstr "Generierte Seiten für {count} {entity_type} in {locale}."

msgid "Generated the listing page for {entity_type} in {locale}."
msgstr "Erzeugt die Auflistungsseite für {entity_type} in {locale}."
msgid ""
"Generated {completed_job_count} out of {total_job_count} items "
"({completed_job_percentage}%)."
msgstr ""

msgid "Generating JSON Schema..."
msgstr "Generiere JSON Schema..."
Expand Down
9 changes: 4 additions & 5 deletions betty/assets/locale/fr-FR/betty.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-02-17 18:26+0000\n"
"POT-Creation-Date: 2024-02-24 13:08+0000\n"
"PO-Revision-Date: 2024-02-08 13:24+0000\n"
"Last-Translator: Bart Feenstra <bart@bartfeenstra.com>\n"
"Language: fr\n"
Expand Down Expand Up @@ -489,10 +489,9 @@ msgstr ""
msgid "Generate site"
msgstr ""

msgid "Generated pages for {count} {entity_type} in {locale}."
msgstr ""

msgid "Generated the listing page for {entity_type} in {locale}."
msgid ""
"Generated {completed_job_count} out of {total_job_count} items "
"({completed_job_percentage}%)."
msgstr ""

msgid "Generating JSON Schema..."
Expand Down
13 changes: 6 additions & 7 deletions betty/assets/locale/nl-NL/betty.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-02-17 18:26+0000\n"
"POT-Creation-Date: 2024-02-24 13:08+0000\n"
"PO-Revision-Date: 2024-02-11 15:31+0000\n"
"Last-Translator: Bart Feenstra <bart@bartfeenstra.com>\n"
"Language: nl\n"
Expand Down Expand Up @@ -567,13 +567,12 @@ msgstr "Genereer pagina's met entiteitsoverzichten"
msgid "Generate site"
msgstr "Genereer site"

msgid "Generated pages for {count} {entity_type} in {locale}."
msgstr "Pagina's voor {count} {entity_type} in het {locale} gegenereerd."

msgid "Generated the listing page for {entity_type} in {locale}."
msgid ""
"Generated {completed_job_count} out of {total_job_count} items "
"({completed_job_percentage}%)."
msgstr ""
"Pagina met het overzicht van alle {entity_type} in het {locale} "
"gegenereerd."
"{completed_job_count} van de {total_job_count} items gegenereerd"
"({completed_job_percentage}%)."

msgid "Generating JSON Schema..."
msgstr "JSON Schema aan het genereren..."
Expand Down
9 changes: 4 additions & 5 deletions betty/assets/locale/uk/betty.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Betty VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-02-17 18:26+0000\n"
"POT-Creation-Date: 2024-02-24 13:08+0000\n"
"PO-Revision-Date: 2024-02-08 13:08+0000\n"
"Last-Translator: Rainer Thieringer <rainerthi@gmail.com>\n"
"Language: uk\n"
Expand Down Expand Up @@ -490,10 +490,9 @@ msgstr ""
msgid "Generate site"
msgstr ""

msgid "Generated pages for {count} {entity_type} in {locale}."
msgstr ""

msgid "Generated the listing page for {entity_type} in {locale}."
msgid ""
"Generated {completed_job_count} out of {total_job_count} items "
"({completed_job_percentage}%)."
msgstr ""

msgid "Generating JSON Schema..."
Expand Down
23 changes: 12 additions & 11 deletions betty/extension/nginx/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,34 @@
from pathlib import Path
from typing import Any

import dill
import docker
from aiofiles.tempfile import TemporaryDirectory, AiofilesContextManagerTempDir
from docker.errors import DockerException

from betty.app import App
from betty.extension.nginx.artifact import generate_dockerfile_file, generate_configuration_file
from betty.extension.nginx.docker import Container
from betty.project import Project
from betty.serve import NoPublicUrlBecauseServerNotStartedError, AppServer


class DockerizedNginxServer(AppServer):
def __init__(self, app: App) -> None:
super().__init__(
# Create a new app so we can modify it later.
dill.loads(dill.dumps(app))
)
from betty.extension import Nginx

project = Project(ancestry=app.project.ancestry)
project.configuration.autowrite = False
project.configuration.configuration_file_path = app.project.configuration.configuration_file_path
project.configuration.update(app.project.configuration)
project.configuration.debug = True
app = App(app.configuration, project)
# Work around https://github.com/bartfeenstra/betty/issues/1056.
app.extensions[Nginx].configuration.https = False
super().__init__(app)
self._container: Container | None = None
self._output_directory: AiofilesContextManagerTempDir[None, Any, Any] | None = None

async def start(self) -> None:
from betty.extension import Nginx

await super().start()
logging.getLogger(__name__).info('Starting a Dockerized nginx web server...')
self._output_directory = TemporaryDirectory()
Expand All @@ -36,10 +41,6 @@ async def start(self) -> None:
docker_directory_path = Path(output_directory_name)
dockerfile_file_path = docker_directory_path / 'Dockerfile'

self._app.project.configuration.debug = True
# Work around https://github.com/bartfeenstra/betty/issues/1056.
self._app.extensions[Nginx].configuration.https = False

await generate_configuration_file(
self._app,
destination_file_path=nginx_configuration_file_path,
Expand Down
Loading

0 comments on commit fbe2700

Please sign in to comment.