0

I've been fighting for three hours now to get this process multithreaded, so that I can display a progress box. I finally got it working, insomuch as the process completes as expected, and all the functions call, including the ones to update the progress indicator on the window.

However, the window never actually displays. This is a PyGObject interface designed in Glade. I am not having fun.

def runCompile(obj):
    compileWindow = builder.get_object("compilingWindow")
    compileWindow.show_all()

    pool = ThreadPool(processes=1)
    async_result = pool.apply_async(compileStrings, ())

    output = async_result.get()
    #output = compileStrings() #THIS IS OLD

    compileWindow.hide()

    return output

As I mentioned, everything works well, except for the fact that the window doesn't appear. Even if I eliminate the compileWindow.hide() command, the window never shows until the process is done. In fact, the whole stupid program freezes until the process is done.

I'm at the end of my rope. Help?

(By the way, the "recommended" processes of using generators doesn't work, as I HAVE to have a return from the "long process".)

CodeMouse92
  • 6,840
  • 14
  • 73
  • 130

2 Answers2

1

I'm not a pyGobject expert and i don't really understand your code. I think that you should post more. Why are you calling the builder in a function? you can call it at the init of the GUI?

Anyways.. It seems that you are having the common multithread problems..

are you using at the startup GObject.threads_init() and Gdk.threads_init() ?

Then, if you want to show a window from a thread you need to use Gdk.threads_enter() and Gdk.threads_leave().

here is an useful doc

  • Not exactly what my program was going for (not that you could know), however, sound advice all the same. See my answer below for a link to the full source code. – CodeMouse92 Nov 16 '14 at 17:35
0

I changed the overall flow of my project, so that may affect it. However, it is imperative that Gtk be given a chance to go through its own main loop, by way of...

if Gtk.events_pending():
    Gtk.main_iteration()

In this instance, I only want to call it once, to ensure the program doesn't hang.

(The entire program source code can be found on SourceForge. The function in question is on line 372 as of this posting, in function compileModel().

CodeMouse92
  • 6,840
  • 14
  • 73
  • 130