add finalizer to stop worker on terminate

This commit is contained in:
Mikhail Epifanov 2024-02-05 23:50:57 +01:00
parent 408c2271a6
commit 2a6c13fc5c
No known key found for this signature in database
2 changed files with 3 additions and 1 deletions

View File

@ -79,7 +79,7 @@ jobs:
- name: Django Testing project
timeout-minutes: 6
run: pytest
run: pytest --junitxml=junit/test-results-${{ matrix.python-version }}.xml
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2

View File

@ -2,6 +2,7 @@ import asyncio
import logging
import multiprocessing
import queue
import weakref
from asyncio import Task
from dataclasses import dataclass
from enum import Enum
@ -49,6 +50,7 @@ class ConnectorManager:
self._queue = multiprocessing.JoinableQueue(maxsize=settings.EXTERNAL_CONNECTORS_QUEUE_SIZE)
self._worker = multiprocessing.Process(target=self.worker, args=(0, self._queue,), daemon=True)
self._worker.start()
self._finalizer = weakref.finalize(self, self.stop)
# Called by post save & post delete signals
def __call__(self, instance: Any, **kwargs) -> None: