Julia: GUI apps by Gtk.jl with Multi-threading and Progress

Appearance in KDE desktop environment

Using Linux, we can use Julia scripts that use multiple CPU cores to do heavy processing work, and monitor progress in a GUI.

The example code is here.

To enable progress updates of the UI, a thread is spawned, to keep the UI thread idle. Any code that tries to update the UI from the main thread will freeze the UI, and block updates from the spawned thread. All UI updates from the spawned thread, must be inside a “g_idle_add” block. Modules that update the UI, must have the UI elements passed to them from the main thread, and have “using Gtk”.

From the spawned thread, UI updates can be sent, and work can be done single threaded or multi threaded. Spawning threads has performance overheads – consider grouping data items to limit the number of spawned threads.

The linked example includes multi-threaded work. Also, the UI layout is superficially changed from the above image, even includes a titlebar icon.

Results are taken from that channel as they arrive, and are used to measure progress for updating the UI. When all results are collected into another channel, an observable is changed, to trigger the collection of the results on the main thread. Things such as plotting graphical results, must be done from the main thread.

MS Windows users: I didnt get Gtk to work on windows. I used Tk instead – which may not have as many features.

Scripts can be added to start menus, for one-click starting. Check out Julia: single click open of GUI app

END

One thought on “Julia: GUI apps by Gtk.jl with Multi-threading and Progress

Leave a comment