re-initialize Application in push workers for windows

This commit is contained in:
Izalia Mae 2024-04-02 15:18:31 -04:00
parent dec7c6a674
commit bd50baa639
2 changed files with 23 additions and 3 deletions

View file

@ -22,7 +22,7 @@ from .cache import get_cache
from .config import Config
from .database import get_database
from .http_client import HttpClient
from .misc import check_open_port, get_resource
from .misc import IS_WINDOWS, check_open_port, get_resource
from .template import Template
from .views import VIEWS
from .views.api import handle_api_path
@ -296,9 +296,14 @@ class CacheCleanupThread(Thread):
class PushWorker(multiprocessing.Process):
def __init__(self, queue: multiprocessing.Queue):
if Application.DEFAULT is None:
raise RuntimeError('Application not setup yet')
multiprocessing.Process.__init__(self)
self.queue = queue
self.shutdown = multiprocessing.Event()
self.path = Application.DEFAULT.config.path
def stop(self) -> None:
@ -310,6 +315,15 @@ class PushWorker(multiprocessing.Process):
async def handle_queue(self) -> None:
if IS_WINDOWS:
app = Application(self.path)
client = app.client
client.open()
app.database.connect()
app.cache.setup()
else:
client = HttpClient()
client.open()
@ -325,6 +339,10 @@ class PushWorker(multiprocessing.Process):
except Exception:
traceback.print_exc()
if IS_WINDOWS:
app.database.disconnect()
app.cache.close()
await client.close()

View file

@ -3,6 +3,7 @@ from __future__ import annotations
import aputils
import json
import os
import platform
import socket
import typing
@ -38,6 +39,7 @@ ResponseType = typing.TypedDict('ResponseType', {
})
IS_DOCKER = bool(os.environ.get('DOCKER_RUNNING'))
IS_WINDOWS = platform.system() == 'Windows'
MIMETYPES = {
'activity': 'application/activity+json',