Reworking how Sanic is run for upgraded Sanic version

This commit is contained in:
Roland 2026-01-22 18:55:12 -07:00
parent bdf5e0856f
commit 399b17ce4e
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
5 changed files with 15 additions and 0 deletions

View file

@ -50,6 +50,10 @@ services:
build:
context: .
dockerfile: docker/api/Dockerfile
environment:
# Sanic 25.x wants 'spawn' but our code uses 'fork' for multiprocessing.
# This tells Sanic to accept the existing start method.
- SANIC_START_METHOD_SET=1
volumes:
- './main.py:/opt/wrolpi/main.py'
- './wrolpi:/opt/wrolpi/wrolpi'

View file

@ -6,6 +6,8 @@ Conflicts=wrolpi-api.service
[Service]
Environment=PYTHONUNBUFFERED=1
# Sanic 25.x wants 'spawn' but our code uses 'fork' for multiprocessing.
Environment=SANIC_START_METHOD_SET=1
ExecStart=/opt/wrolpi/venv/bin/python -m sanic main:api_app --host 0.0.0.0 --port 8081 -w 2 --reload --debug
ExecReload=/bin/kill -HUP $MAINPID
Group=wrolpi

View file

@ -6,6 +6,8 @@ Conflicts=wrolpi-api-dev.service
[Service]
Environment=PYTHONUNBUFFERED=1
# Sanic 25.x wants 'spawn' but our code uses 'fork' for multiprocessing.
Environment=SANIC_START_METHOD_SET=1
ExecStart=/opt/wrolpi/venv/bin/python -O -m sanic main:api_app --host 0.0.0.0 --port 8081 -w 5
ExecReload=/bin/kill -HUP $MAINPID
Group=wrolpi

View file

@ -13,6 +13,7 @@ libzim==3.5.0
mock==5.1.0
psutil==6.0.0
psycopg2-binary==2.9.9
pydantic>=2.0.0
pypdf==6.4.0
pytest-asyncio==0.24.0
pytest-xdist==3.5.0

View file

@ -17,6 +17,12 @@ from wrolpi.vars import PYTEST
logger = logger.getChild(__name__)
# Sanic 25.x wants to use 'spawn' as the multiprocessing start method, but our code
# uses 'fork' extensively (via multiprocessing.Manager, Event, Queue, etc.).
# Tell Sanic to use 'fork' and that the start method is already configured.
Sanic.start_method = "fork"
Sanic.START_METHOD_SET = True
# The only Sanic App, this is imported all over.
api_app = Sanic(name='api_app', log_config=LOGGING_CONFIG)