# Visualize long pmap process using Gtk.ProgressBarLeaf

**URL:** https://discourse.julialang.org/t/visualize-long-pmap-process-using-gtk-progressbarleaf/93792
**Category:** Performance
**Tags:** gtk
**Created:** [January 30, 2023, 8:51pm UTC](https://discourse.julialang.org/t/visualize-long-pmap-process-using-gtk-progressbarleaf/93792 "2023-01-30T20:51:53Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![abbe](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@abbe](https://discourse.julialang.org/u/abbe)
#### Post date: [January 30, 2023, 8:51pm UTC](https://discourse.julialang.org/t/visualize-long-pmap-process-using-gtk-progressbarleaf/93792/1 "2023-01-30T20:51:53Z")

</div>

Hey all,  
I was wondering if it is possible to view the progress of the pmap function using GtkProgressBar when pmap is running on multiple (or all) processes.

```julia
using Distributed, Statistics
id = addprocs()
@everywhere begin
    using Gtk, Images
    global base_id = myid()
    global cnt = 0
end
btn = GtkButton("Open directory")
ent = GtkEntry()
pb = GtkProgressBar()
grid = GtkGrid()
grid[1,1] = btn
grid[1:5,2] = ent
grid[1:5,3] = pb

@everywhere function ImageHeight(name, arr_length)
    img = load(name)
    sz = size(img)
    ratio = cnt / arr_length
    global cnt += 1
    update_gtkprogressbar(ratio)
    return sz[1]
end

b = WorkerPool(workers()[2:end])
signal_connect(btn, "clicked") do widget   
    dir = open_dialog("Select Image Folder", action=GtkFileChooserAction.SELECT_FOLDER)
    dir = dir.*"\\"
    @async begin
        lst = readdir(dir)
        len = length(lst)
        hh = pmap(ImageHeight, b, dir.*lst, len)
        aver = mean(hh)
        remotecall_fetch(set_gtk_property!, base_id, ent, :text, "Average height of images: $aver")
    end
end

# see https://gitlab.com/kodintent/julia_template_gui_progress_multithreading/-/tree/main
@everywhere function update_gtkprogressbar(frac::AbstractFloat)
    Gtk.GLib.g_idle_add(nothing) do update_ui
        remotecall_fetch(set_gtk_property!, base_id, pb, :fraction, frac)
        Cint(false) # MUST HAVE, MUST BE FALSE
    end
end

win = GtkWindow(grid, "Get height of images", 500, 200)
showall(win)

```

You can see that I have a problem updating the Gtk GUI from another process because Gtk is defined on the base process. The ImageHeight function is just a demonstration, in fact it should be much more complex.  
My point is to show the progress of a long pmap process using the progress bar.

Thanks for ideas …
