mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-05 22:57:40 +03:00
fix: run Frigate+ API calls in thread pool to prevent event loop blocking
The send_to_plus and set_false_positive handlers are async but call synchronous PlusApi methods (which use the requests library) directly, blocking the asyncio event loop for 10-16 seconds during image upload. This stalls all other HTTP requests to Frigate. Wrap upload_image, add_annotation, and add_false_positive calls in asyncio.to_thread() so they run in a thread pool without blocking. Fixes #16566
This commit is contained in:
parent
e873cd6837
commit
46632c28d6
@ -1,5 +1,6 @@
|
||||
"""Event apis."""
|
||||
|
||||
import asyncio
|
||||
import base64
|
||||
import datetime
|
||||
import json
|
||||
@ -11,7 +12,6 @@ from functools import reduce
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
from urllib.parse import unquote
|
||||
import asyncio
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
@ -1125,7 +1125,9 @@ async def send_to_plus(request: Request, event_id: str, body: SubmitPlusBody = N
|
||||
)
|
||||
|
||||
try:
|
||||
plus_id = await asyncio.to_thread(request.app.frigate_config.plus_api.upload_image, image, event.camera)
|
||||
plus_id = await asyncio.to_thread(
|
||||
request.app.frigate_config.plus_api.upload_image, image, event.camera
|
||||
)
|
||||
except Exception as ex:
|
||||
logger.exception(ex)
|
||||
return JSONResponse(
|
||||
@ -1232,7 +1234,8 @@ async def false_positive(request: Request, event_id: str):
|
||||
)
|
||||
|
||||
try:
|
||||
request.app.frigate_config.plus_api.add_false_positive(
|
||||
await asyncio.to_thread(
|
||||
request.app.frigate_config.plus_api.add_false_positive,
|
||||
event.plus_id,
|
||||
region,
|
||||
box,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user