darktable-org / darktable-org/lua-scripts

help wanted: strange / unknown behaviour of gui.create_job

Aperta
#381 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Lua
Stelle
219
Fork
142
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I'm currently writing (or, trying to write 🙄) a lua script that will generate the preview cache for selected images (without leaving dt to start the external program...). Basically, it seems to work but I see two strange things that I don't understand right now.

First, the essential parts of my script:

local function stop_job( job )
  job.valid = false
end

local function create_previews()
  job = dt.gui.create_job( "generating previews", true, stop_job )
  local images = dt.gui.action_images
  for i,image in pairs(images) do
    if job.valid then
      image:generate_cache( true, 0, 8 )
      job.percent = i / #images
      dt.control.sleep( 1 ) -- without this, the job cannot be aborted
    else
      break
    end
  end
  if job.valid then -- without this, dt crashes with an exception in dt_pthread_mutex_destroy() after aborting the job
    job.valid = false
  end
end

the create_previews function will be called from a registered action.

My two questions:

  1. Without the sleep() I cannot stop the running job. After starting the job, the progress bar is shown and when I hit the 'X' nothing happens until the for loop processed all images. Then the stop_job() is called. With the sleep the stop_job is called after processing the current image and the job terminates as desired.

  2. When I set the job.valid to false after the loop it only works as long as the job is not terminated via the stop_job function. As this already sets the job to invalid I guess it is already destroyed and in the second job.valid=false dt crashes with an exception in dt_pthread_mutex_destroy.

Both phenomena are completely understandable, but: I see a lot of scripts that execute job.valid=false twice (when aborted) and seem to rely on stopping without a call to sleep(). Hmmm. What I'm missing here?

I hope you can clarify this,
thanks a lot!
Christian

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con l’azione registrata mostrata e riproduci la cancellazione di dt.gui.create_job sia con sia senza dt.control.sleep. Traccia il ciclo di vita di job.valid intorno a stop_job e all’assegnazione finale, utilizzando l’implementazione della Lua API o gli script esistenti menzionati dall’issue. Il lavoro è completato quando il comportamento della cancellazione e l’uso sicuro del ciclo di vita del job sono chiariti o corretti senza il crash segnalato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
lua
Ambito
api
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.