mirror of
https://github.com/azaion/detections.git
synced 2026-04-22 05:26:32 +00:00
Replace threading.Lock with cython.pymutex and upgrade Cython to 3.2.4
Made-with: Cursor
This commit is contained in:
@@ -7,10 +7,12 @@ cdef enum AIAvailabilityEnum:
|
||||
WARNING = 300
|
||||
ERROR = 500
|
||||
|
||||
from cython cimport pymutex
|
||||
|
||||
cdef class AIAvailabilityStatus:
|
||||
cdef int status
|
||||
cdef str error_message
|
||||
cdef object _lock
|
||||
cdef pymutex _lock
|
||||
|
||||
cdef bytes serialize(self)
|
||||
cdef set_status(self, int status, str error_message=*)
|
||||
@@ -1,6 +1,6 @@
|
||||
cimport cython
|
||||
cimport constants_inf
|
||||
import msgpack
|
||||
from threading import Lock
|
||||
|
||||
AIStatus2Text = {
|
||||
AIAvailabilityEnum.NONE: "None",
|
||||
@@ -15,41 +15,31 @@ AIStatus2Text = {
|
||||
cdef class AIAvailabilityStatus:
|
||||
def __init__(self):
|
||||
self.status = AIAvailabilityEnum.NONE
|
||||
self.error_message = None
|
||||
self._lock = Lock()
|
||||
self.error_message = ""
|
||||
|
||||
def __str__(self):
|
||||
self._lock.acquire()
|
||||
try:
|
||||
with self._lock:
|
||||
status_text = AIStatus2Text.get(self.status, "Unknown")
|
||||
error_text = self.error_message if self.error_message else ""
|
||||
return f"{status_text} {error_text}"
|
||||
finally:
|
||||
self._lock.release()
|
||||
|
||||
cdef bytes serialize(self):
|
||||
self._lock.acquire()
|
||||
try:
|
||||
with self._lock:
|
||||
return msgpack.packb({
|
||||
"s": self.status,
|
||||
"m": self.error_message
|
||||
})
|
||||
finally:
|
||||
self._lock.release()
|
||||
|
||||
cdef set_status(self, int status, str error_message=None):
|
||||
cdef set_status(self, int status, str error_message=""):
|
||||
log_message = ""
|
||||
self._lock.acquire()
|
||||
try:
|
||||
with self._lock:
|
||||
self.status = status
|
||||
self.error_message = error_message
|
||||
status_text = AIStatus2Text.get(self.status, "Unknown")
|
||||
error_text = self.error_message if self.error_message else ""
|
||||
log_message = f"{status_text} {error_text}"
|
||||
finally:
|
||||
self._lock.release()
|
||||
|
||||
if error_message is not None:
|
||||
if error_message:
|
||||
constants_inf.logerror(<str>error_message)
|
||||
else:
|
||||
constants_inf.log(<str>log_message)
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
fastapi
|
||||
uvicorn[standard]
|
||||
Cython==3.1.3
|
||||
Cython==3.2.4
|
||||
opencv-python==4.10.0.84
|
||||
numpy==2.3.0
|
||||
onnxruntime==1.22.0
|
||||
|
||||
Reference in New Issue
Block a user