Upgrading Sanic and yt-dlp. Major changes occurred because Sanic changed how multiprocessing works.

Python 3.11 is now required, old versions were causing unpredictability in tests.  (Sanic does not yet
support 3.12)

Sanic has been upgraded to 23.6.0, which is the latest version that avoids this bug:
 https://github.com/sanic-org/sanic/issues/2921

New strategy for multiprocessing is to create all multiprocessing tools in one process, then fork
to other processes.  The previous strategy was to declare multiprocessing tools at the top of every
file, or wherever they were needed at import/creation.  Now all multiprocessing tools are attached to the
app.shared_ctx.  This means `api_app` is imported in many, many places.

This forced a change in how the DownloadManager works.  Previously, it would continually run
download workers which would pull downloads from a multiprocessing.Queue.  Now, a single worker checks
for new downloads and sends a Sanic signal.

Flags have been reworked to use the `api_app`.  I removed the `which` flag functionality because the
`which` are called at import and needed their own multiprocessing.Event.
This commit is contained in:
Roland 2024-04-17 11:25:26 -06:00
parent 2c127a03f5
commit 58de8c7c5b
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
65 changed files with 1238 additions and 1058 deletions

View file

@ -1,21 +1,21 @@
from http import HTTPStatus
from pathlib import Path
from sanic import Request, response
from sanic import Request, response, Blueprint
from sanic_ext import validate
from sanic_ext.extensions.openapi import openapi
from modules.map import lib, schema
from wrolpi import flags
from wrolpi.api_utils import json_response
from wrolpi.common import wrol_mode_check, get_media_directory, background_task
from wrolpi.errors import ValidationError
from wrolpi.root_api import get_blueprint, json_response
from wrolpi.vars import PYTEST, DOCKERIZED
bp = get_blueprint('Map', '/api/map')
map_bp = Blueprint('Map', '/api/map')
@bp.post('/import')
@map_bp.post('/import')
@openapi.definition(
summary='Import PBF/dump map files',
body=schema.ImportPost,
@ -38,12 +38,12 @@ async def import_pbfs(_: Request, body: schema.ImportPost):
return response.empty()
@bp.get('/files')
@map_bp.get('/files')
@openapi.description('Find any map files, get their import status')
def get_files_status(_: Request):
def get_files_status(request: Request):
paths = lib.get_import_status()
paths = sorted(paths, key=lambda i: str(i.path))
pending = lib.IMPORTING.get('pending')
pending = request.app.shared_ctx.map_importing.get('pending')
if pending:
pending = [Path(i).relative_to(get_media_directory()) for i in pending]
body = dict(