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