File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
pkg/workloads/cortex/serve Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 5151API_LIVENESS_UPDATE_PERIOD = 5 # seconds
5252
5353
54+ request_thread_pool = ThreadPoolExecutor (max_workers = int (os .environ ["CORTEX_THREADS_PER_PROCESS" ]))
5455loop = asyncio .get_event_loop ()
55- loop .set_default_executor (
56- ThreadPoolExecutor (max_workers = int (os .environ ["CORTEX_THREADS_PER_PROCESS" ]))
57- )
56+ loop .set_default_executor (request_thread_pool )
5857
5958app = FastAPI ()
6059
@@ -239,7 +238,15 @@ def get_summary():
239238 return response
240239
241240
241+ # this exists so that the user's __init__() can be executed by the request thread pool, which helps
242+ # to avoid errors that occur when the user's __init__() function must be called by the same thread
243+ # which executes predict(). This only avoids errors if threads_per_worker == 1
242244def start ():
245+ future = request_thread_pool .submit (start_fn )
246+ return future .result ()
247+
248+
249+ def start_fn ():
243250 cache_dir = os .environ ["CORTEX_CACHE_DIR" ]
244251 provider = os .environ ["CORTEX_PROVIDER" ]
245252 spec_path = os .environ ["CORTEX_API_SPEC" ]
You can’t perform that action at this time.
0 commit comments