Hi,

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:


localfunctionstop_job( job )
  job.valid=false
end
localfunctioncreate_previews()
  job =dt.gui.create_job( "generating previews", true, stop_job )
localimages =dt.gui.action_images
fori,image inpairs(images) do
ifjob.validthen
      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
ifjob.validthen-- 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

--
Christian Birzer
christ...@christianbirzer.de
www.ChristianBirzer.de
www.500px.com/ChristianBirzer
www.flickr.com/ChristianBirzer
www.facebook.com/Birzer.Christian
www.instagram.com/birzer.christian

___________________________________________________________________________
darktable developer mailing list
to unsubscribe send a mail to darktable-dev+unsubscr...@lists.darktable.org

Reply via email to