Public `JobContext.create_task()` for background tasks that end with the job
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 62/100
Direzione di ricerca
Parti dal contesto del job e dal suo metodo privato _track_pending_task(), oltre che dal percorso di shutdown che annulla i task tracciati dopo i callback di shutdown. Leggi come delete_room e add_sip_participant usano questo tracciamento. Il lavoro è completo quando esiste un create_task() pubblico che mantiene un riferimento, registra i fallimenti e viene annullato allo shutdown, con test per l'ordine di cancellazione e il logging degli errori.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Feature Type: Would make my life easier
What we're trying to do
Our voice agent starts many small background tasks during a call. For example: a silence
watchdog, a loop that saves call quality stats, and a prefetch of some data.
When the job ends, these tasks should stop too. If a task fails, we want to see the error
in the logs.
What we do today
The framework already does this for its own tasks (delete_room, add_sip_participant).
It uses JobContext._track_pending_task(). That method is private, so we copy the idea in
our own code:
bg_tasks: set[asyncio.Task] = set()
def track_task(coro):
task = asyncio.ensure_future(coro)
bg_tasks.add(task)
task.add_done_callback(bg_tasks.discard)
return task
# later, in our shutdown code
for task in bg_tasks:
task.cancel()
We have this in two entrypoints. It works, but every user has to write it, and it is easy
to get wrong. Ours does not log errors, for example.
The small API we'd like
task = ctx.create_task(watch_silence(), name="silence_watchdog")
It would just call asyncio.create_task() and then self._track_pending_task(). So the job:
- keeps a reference to the task, so it is not garbage collected,
- logs the error if the task fails,
- cancels the task if it is still running when the job ends.
It returns the normal asyncio.Task, so you can still await or cancel it yourself.
The job already cancels these tasks at the end of shutdown, after the shutdown callbacks.
This new method uses that same step. Nothing about shutdown changes.
utils.aio.TaskSet is close, but it is not tied to the job, so nothing cancels its tasks
at the end.
Question
Would you accept a PR for this? I have a small change ready: the method with a
docstring, plus two tests (the task is cancelled after the shutdown callbacks, and a failing
task is logged). Happy to change the name or put it somewhere else if you prefer.
- Lingua principale
- Python
- Stelle
- 14.6k
- Fork
- 3.9k
- Merge medio
- 2g 23h
- PR unite (30g)
- 263
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di livekit/agents
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
livekit/agents#8284 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
ci: unit tests pin Python 3.12 while the package advertises 3.14 supportForse di nuovo libera @huong8373tt-beep l’ha presa 8 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
livekit/agents#8231 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Assistant markup is stripped from chat history when expressive mode is offForse già presa @ShivamSharma43 l’ha presa 29 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
livekit/agents#7647 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
docs: openai.LLM vs openai.responses.LLM for HTTP OpenAI-compat hostsForse di nuovo libera @AbarnaaSree l’ha presa 69 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
livekit/agents#7022 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di livekit/agents
Issue simili
-
documentation good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
MarketSquare/robotframework-browser#5479 ·
I maintainer di solito rispondono entro 1 giorno
-
Visual COBOL: missing 11.0 and 12.0, and 9.0 date differs from Rocket Software's lifecycle pageAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
endoflife-date/endoflife.date#11561 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
OCA/l10n-brazil#5602 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation review-2.0.0
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
dkuenzel/meshcore-home-gateway#106 ·
I maintainer di solito rispondono entro 1 giorno