Search code examples
pythoncommand-linepygtkgraphicsmagick

Pygtk threading long command line process


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 multi-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.


Solution

  • 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