mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-02 13:24:53 +03:00
Fix export deadlock by replacing preexec_fn with nice command (#22641)
Some checks are pending
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
Some checks are pending
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
subprocess.run() with preexec_fn forces Python to use fork() instead of posix_spawn(). In Frigate's main process (75+ threads), fork() creates a child that inherits locked mutexes from other threads. The child may deadlocks e.g. on a pysqlite3 mutex before it can exec() ffmpeg. Replace preexec_fn=lower_priority (which calls os.nice(19)) with prefixing the ffmpeg command with "nice -n 19", achieving the same priority reduction without requiring preexec_fn. This allows Python to use posix_spawn() which is safe in multithreaded processes. Fixes both the primary export path and the CPU fallback retry path.
This commit is contained in:
parent
0cf9d7d5b1
commit
909b40ba96
@ -85,10 +85,6 @@ def validate_ffmpeg_args(args: str) -> tuple[bool, str]:
|
|||||||
return True, ""
|
return True, ""
|
||||||
|
|
||||||
|
|
||||||
def lower_priority() -> None:
|
|
||||||
os.nice(PROCESS_PRIORITY_LOW)
|
|
||||||
|
|
||||||
|
|
||||||
class PlaybackSourceEnum(str, Enum):
|
class PlaybackSourceEnum(str, Enum):
|
||||||
recordings = "recordings"
|
recordings = "recordings"
|
||||||
preview = "preview"
|
preview = "preview"
|
||||||
@ -439,10 +435,9 @@ class RecordingExporter(threading.Thread):
|
|||||||
return
|
return
|
||||||
|
|
||||||
p = sp.run(
|
p = sp.run(
|
||||||
ffmpeg_cmd,
|
["nice", "-n", str(PROCESS_PRIORITY_LOW)] + ffmpeg_cmd,
|
||||||
input="\n".join(playlist_lines),
|
input="\n".join(playlist_lines),
|
||||||
encoding="ascii",
|
encoding="ascii",
|
||||||
preexec_fn=lower_priority,
|
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -467,10 +462,9 @@ class RecordingExporter(threading.Thread):
|
|||||||
)
|
)
|
||||||
|
|
||||||
p = sp.run(
|
p = sp.run(
|
||||||
ffmpeg_cmd,
|
["nice", "-n", str(PROCESS_PRIORITY_LOW)] + ffmpeg_cmd,
|
||||||
input="\n".join(playlist_lines),
|
input="\n".join(playlist_lines),
|
||||||
encoding="ascii",
|
encoding="ascii",
|
||||||
preexec_fn=lower_priority,
|
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user