make python app load a bit eariler, making startup a bit faster

This commit is contained in:
Alex Bezdieniezhnykh
2025-02-13 18:13:15 +02:00
parent e329e5bb67
commit cfd5483a18
31 changed files with 183 additions and 124 deletions
+15 -15
View File
@@ -9,16 +9,10 @@ from annotation cimport Annotation
from inference cimport Inference
from remote_command cimport RemoteCommand, CommandType
from remote_command_handler cimport RemoteCommandHandler
from credentials cimport Credentials
from file_data cimport FileData
from user cimport User
cdef class ParsedArguments:
cdef str email, password, folder;
def __init__(self, str email, str password, str folder):
self.email = email
self.password = password
self.folder = folder
cdef class CommandProcessor:
cdef ApiClient api_client
cdef RemoteCommandHandler remote_handler
@@ -26,8 +20,8 @@ cdef class CommandProcessor:
cdef bint running
cdef Inference inference
def __init__(self, args: ParsedArguments):
self.api_client = ApiClient(args.email, args.password, args.folder)
def __init__(self):
self.api_client = ApiClient()
self.remote_handler = RemoteCommandHandler(self.on_command)
self.inference_queue = Queue(maxsize=constants.QUEUE_MAXSIZE)
self.remote_handler.start()
@@ -49,11 +43,10 @@ cdef class CommandProcessor:
cdef on_command(self, RemoteCommand command):
try:
if command.command_type == CommandType.GET_USER:
self.get_user(command, self.api_client.get_user())
if command.command_type == CommandType.LOGIN:
self.login(command)
elif command.command_type == CommandType.LOAD:
response = self.api_client.load_bytes(command.filename)
self.remote_handler.send(command.client_id, response)
self.load_file(command)
elif command.command_type == CommandType.INFERENCE:
self.inference_queue.put(command)
elif command.command_type == CommandType.STOP_INFERENCE:
@@ -66,9 +59,16 @@ cdef class CommandProcessor:
except Exception as e:
print(f"Error handling client: {e}")
cdef get_user(self, RemoteCommand command, User user):
cdef login(self, RemoteCommand command):
cdef User user
self.api_client.credentials = Credentials.from_msgpack(command.data)
user = self.api_client.get_user()
self.remote_handler.send(command.client_id, user.serialize())
cdef load_file(self, RemoteCommand command):
response = self.api_client.load_bytes(FileData.from_msgpack(command.data))
self.remote_handler.send(command.client_id, response)
cdef on_annotation(self, RemoteCommand cmd, Annotation annotation):
data = annotation.serialize()
self.remote_handler.send(cmd.client_id, data)