Skip to content

Commit 1b06414

Browse files
author
maebahesioru
committed
perf: lazy-load inspect/ThreadPoolExecutor, cap log queue at 1000
1 parent 1c49780 commit 1b06414

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/manager/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import sys
88
import threading
99
import time
10-
from concurrent.futures import ThreadPoolExecutor
1110
from typing import Any, Dict, List, Optional
1211

1312
from fastapi import WebSocket
@@ -43,7 +42,7 @@
4342
class ServiceManager:
4443
def __init__(self):
4544
self.process: Optional[subprocess.Popen] = None
46-
self.log_queue: asyncio.Queue = asyncio.Queue()
45+
self.log_queue: asyncio.Queue = asyncio.Queue(maxsize=1000)
4746
self.active_connections: List[WebSocket] = []
4847
self.output_thread: Optional[threading.Thread] = None
4948
self.stop_event = threading.Event()
@@ -523,6 +522,7 @@ def kill_process(process: subprocess.Popen) -> None:
523522
if self.is_worker_mode:
524523
processes = list(self.worker_processes.values())
525524
if processes:
525+
from concurrent.futures import ThreadPoolExecutor
526526
with ThreadPoolExecutor(
527527
max_workers=max(1, len(processes))
528528
) as executor:

src/worker/pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import inspect
32
import json
43
import logging
54
import os
@@ -155,6 +154,7 @@ def init_from_config(self):
155154
logger.info(f"Loaded {len(self.workers)} workers from config")
156155

157156
def _dispatch_listener_result(self, result: Any):
157+
import inspect
158158
if not inspect.isawaitable(result):
159159
return
160160
try:

0 commit comments

Comments
 (0)