Skip to content

Investigate and fix potential GTK GUI freeze during connection refresh #33

@TheZupZup

Description

@TheZupZup

Overview

The GTK GUI uses GLib.timeout_add_seconds(2, self.refresh_connections) to refresh every 2 seconds. Inside refresh_connections(), it calls get_outgoing_connections() which iterates over all system processes via psutil — on the GTK main thread.

GTK is single-threaded. If get_outgoing_connections() takes longer than ~100ms, the UI will visibly stutter or freeze during the refresh.

This may not be a problem on all systems, but it's a structural risk worth measuring.

What needs to be done

  • Benchmark get_outgoing_connections() locally on a system with 50+ active connections — measure average execution time with time.perf_counter()
  • If the call consistently takes < 50ms: document this finding in a comment near the refresh code and close this issue — no fix needed
  • If the call takes > 100ms regularly: move it to a background thread:
    • Use threading.Thread(target=self._refresh_worker, daemon=True)
    • Have the worker call get_outgoing_connections() and post results back via GLib.idle_add(self._update_ui, connections)
    • Never touch GTK widgets from the background thread

Goal

Either confirm the current approach is fast enough and document it, or implement background threading to keep the UI responsive.

Notes

The GTK GLib.idle_add() pattern is the standard way to post results from a thread back to the GTK main loop. The worker thread must never call any Gtk.* methods directly.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions