You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
# Copyright (C) 2018-2022 Intel Corporation
|
|
# Copyright (C) 2022 CVAT.ai Corporation
|
|
#
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
from rq import Worker
|
|
|
|
import cvat.utils.remote_debugger as debug
|
|
|
|
|
|
DefaultWorker = Worker
|
|
|
|
|
|
class BaseDeathPenalty:
|
|
def __init__(self, timeout, exception, **kwargs):
|
|
pass
|
|
|
|
def __enter__(self):
|
|
pass
|
|
|
|
def __exit__(self, exc_type, exc_value, traceback):
|
|
pass
|
|
|
|
|
|
class SimpleWorker(Worker):
|
|
"""
|
|
Allows to work with at most 1 worker thread. Useful for debugging.
|
|
"""
|
|
|
|
death_penalty_class = BaseDeathPenalty
|
|
|
|
def main_work_horse(self, *args, **kwargs):
|
|
raise NotImplementedError("Test worker does not implement this method")
|
|
|
|
def execute_job(self, *args, **kwargs):
|
|
"""Execute job in same thread/process, do not fork()"""
|
|
return self.perform_job(*args, **kwargs)
|
|
|
|
|
|
if debug.is_debugging_enabled():
|
|
class RemoteDebugWorker(SimpleWorker):
|
|
"""
|
|
Support for VS code debugger
|
|
"""
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
self.__debugger = debug.RemoteDebugger()
|
|
super().__init__(*args, **kwargs)
|
|
|
|
def execute_job(self, *args, **kwargs):
|
|
"""Execute job in same thread/process, do not fork()"""
|
|
self.__debugger.attach_current_thread()
|
|
|
|
return super().execute_job(*args, **kwargs)
|
|
|
|
DefaultWorker = RemoteDebugWorker
|