Skip to content

Commit

Permalink
Refactor multiprocessing compatibility into general kolibri utils mod…
Browse files Browse the repository at this point in the history
…ule.
  • Loading branch information
rtibbles committed Nov 3, 2024
1 parent 4bda163 commit 0c328bf
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions kolibri/core/tasks/test/taskrunner/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from kolibri.core.tasks import compat
from kolibri.utils import multiprocessing_compat


@pytest.fixture(params=[False, True], autouse=True)
Expand All @@ -24,7 +24,7 @@ class local(object):
from threading import local # noqa
from concurrent.futures import ThreadPoolExecutor as PoolExecutor # noqa

monkeypatch.setattr(compat, "Thread", Thread)
monkeypatch.setattr(compat, "Event", Event)
monkeypatch.setattr(compat, "local", local)
monkeypatch.setattr(compat, "PoolExecutor", PoolExecutor)
monkeypatch.setattr(multiprocessing_compat, "Thread", Thread)
monkeypatch.setattr(multiprocessing_compat, "Event", Event)
monkeypatch.setattr(multiprocessing_compat, "local", local)
monkeypatch.setattr(multiprocessing_compat, "PoolExecutor", PoolExecutor)
2 changes: 1 addition & 1 deletion kolibri/core/tasks/test/taskrunner/test_job_running.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pytest

from kolibri.core.tasks.compat import Event
from kolibri.core.tasks.exceptions import JobNotFound
from kolibri.core.tasks.job import Job
from kolibri.core.tasks.job import State
Expand All @@ -13,6 +12,7 @@
from kolibri.core.tasks.utils import get_current_job
from kolibri.core.tasks.utils import import_path_to_callable
from kolibri.core.tasks.worker import Worker
from kolibri.utils.multiprocessing_compat import Event


@pytest.fixture
Expand Down
6 changes: 3 additions & 3 deletions kolibri/core/tasks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

from kolibri.core.sqlite.utils import check_sqlite_integrity
from kolibri.core.sqlite.utils import repair_sqlite_db
from kolibri.core.tasks import compat
from kolibri.core.tasks.exceptions import UserCancelledError
from kolibri.utils import conf
from kolibri.utils import multiprocessing_compat
from kolibri.utils.options import FD_PER_THREAD
from kolibri.utils.system import get_fd_limit

Expand All @@ -27,7 +27,7 @@
# An object on which to store data about the current job
# So far the only use is to track the job, but other metadata
# could be added.
current_state_tracker = SimpleLazyObject(compat.local)
current_state_tracker = SimpleLazyObject(multiprocessing_compat.local)


def get_current_job():
Expand Down Expand Up @@ -76,7 +76,7 @@ def __init__(self, func, thread_name, wait_between_runs=1, *args, **kwargs):
:param thread_name: the name of the thread to use during logging and debugging
:param wait_between_runs: how many seconds to wait in between func calls.
"""
self.shutdown_event = compat.Event()
self.shutdown_event = multiprocessing_compat.Event()
self.thread_name = thread_name
self.thread_id = uuid.uuid4().hex
self.logger = logging.getLogger(
Expand Down
2 changes: 1 addition & 1 deletion kolibri/core/tasks/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

from django.db import connection as django_connection

from kolibri.core.tasks.compat import PoolExecutor
from kolibri.core.tasks.constants import Priority
from kolibri.core.tasks.storage import Storage
from kolibri.core.tasks.utils import db_connection
from kolibri.core.tasks.utils import InfiniteLoopThread
from kolibri.utils.multiprocessing_compat import PoolExecutor

logger = logging.getLogger(__name__)

Expand Down
File renamed without changes.

0 comments on commit 0c328bf

Please sign in to comment.