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 51
51
API_LIVENESS_UPDATE_PERIOD = 5 # seconds
52
52
53
53
54
+ request_thread_pool = ThreadPoolExecutor (max_workers = int (os .environ ["CORTEX_THREADS_PER_PROCESS" ]))
54
55
loop = 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 )
58
57
59
58
app = FastAPI ()
60
59
@@ -239,7 +238,15 @@ def get_summary():
239
238
return response
240
239
241
240
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
242
244
def start ():
245
+ future = request_thread_pool .submit (start_fn )
246
+ return future .result ()
247
+
248
+
249
+ def start_fn ():
243
250
cache_dir = os .environ ["CORTEX_CACHE_DIR" ]
244
251
provider = os .environ ["CORTEX_PROVIDER" ]
245
252
spec_path = os .environ ["CORTEX_API_SPEC" ]
You can’t perform that action at this time.
0 commit comments