I am in PyGtk on Windows. My program converts PDF's to images using GraphicsMagick then displays the image. The conversion can be very long on mult开发者_JAVA技巧i-page PDF's so the program has to wait for the command line to return and I need to get around this and allow the user to use the GUI while the image is created. My attempts to use gtk's threading and python's threading have not worked so far, is there a way to easily call the GraphicsMagick conversion as a background process and returnot wait for it to return?
I am using subprocess(command) to perform the conversion from the command line.
Just use subprocess.Popen:
import subprocess
subprocess.Popen(["command", "arg1", "arg2"])
For more information see: http://docs.python.org/library/subprocess.html#using-the-subprocess-module
If you really need to use threads use gtk.gdk.threads_init()
before gtk.main()
http://library.gnome.org/devel/pygtk/stable/gdk-functions.html#function-gdk--threads-init
You could use an idle function that calls subprocess.Popen()
and returns True
if there are still pages left to process. That means it will be called again at the next available opportunity. When you are finished with the pages, you can return False
from the idle function and it will not be called anymore.
精彩评论