Fix UnboundLocalError in cleanup function
The cleanup() callback was trying to delete generator_worker and out_writer_worker unconditionally, but these variables are only defined in certain code paths. This caused UnboundLocalError when cleanup was called after requests that didn't create these workers. Wrap the deletions in try/except blocks to handle cases where the variables weren't created.
This commit is contained in:
parent
bb9823f6d0
commit
4576afac39
1 changed files with 9 additions and 2 deletions
11
speech.py
11
speech.py
|
|
@ -734,8 +734,15 @@ async def generate_speech(request: GenerateSpeechRequest):
|
|||
|
||||
def cleanup():
|
||||
ffmpeg_proc.kill()
|
||||
del generator_worker
|
||||
del out_writer_worker
|
||||
# Only delete workers if they were created
|
||||
try:
|
||||
del generator_worker
|
||||
except NameError:
|
||||
pass
|
||||
try:
|
||||
del out_writer_worker
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
return StreamingResponse(content=ffmpeg_proc.stdout, media_type=media_type, background=cleanup)
|
||||
# Use Silero for tts-1-silero
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue