Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How can I block or delay system shutdown in Linux using a Qt (PySide6) application?

How can I block or delay system shutdown in Linux using a Qt (PySide6) application?

Scheduled Pinned Locked Moved Unsolved Qt for Python
qt for pythonpyside
5 Posts 3 Posters 207 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Ghost-Uchiha
    wrote on 4 Apr 2025, 10:49 last edited by
    #1

    Hi everyone,

    I'm developing a cross-platform desktop application using PySide6 (Qt for Python) on Linux (Ubuntu 22.04, GNOME). One of the key features of the application involves running critical tasks (e.g., backups), during which I want to temporarily block or delay system shutdown — especially if initiated via the GUI (like GNOME’s power-off menu).


    What I’ve tried so far:

    1. Using systemd-inhibit

      • It works for terminal-triggered shutdowns (systemctl poweroff), but GUI shutdown dialogs ignore it.
    2. D-Bus (logind/org.freedesktop.login1)

      • Acquired inhibitor locks via D-Bus using Inhibit() on org.freedesktop.login1.Manager.
      • Successfully prevents terminal shutdowns, but again, GUI shutdown is unaffected.
    3. GNOME Session Manager

      • Explored using org.gnome.SessionManager’s Inhibit() method.
      • It works only on GNOME, not across other DEs like KDE or XFCE.

    The requirement:

    • Must be non-root, i.e., work in user space.
    • Must not require modifying system-level files, polkit rules, or shutdown scripts.
    • Should work across multiple desktop environments if possible.
    • Goal is to inform or prevent shutdown temporarily during a critical operation, then release the block once done.

    Questions:

    • Is there a Qt-native or Qt-compatible way to block or delay system shutdown while a long-running task is active?
    • Are there any Qt APIs or DBus wrappers you recommend for this use case?
    J 1 Reply Last reply 4 Apr 2025, 11:09
    0
    • G Ghost-Uchiha
      4 Apr 2025, 10:49

      Hi everyone,

      I'm developing a cross-platform desktop application using PySide6 (Qt for Python) on Linux (Ubuntu 22.04, GNOME). One of the key features of the application involves running critical tasks (e.g., backups), during which I want to temporarily block or delay system shutdown — especially if initiated via the GUI (like GNOME’s power-off menu).


      What I’ve tried so far:

      1. Using systemd-inhibit

        • It works for terminal-triggered shutdowns (systemctl poweroff), but GUI shutdown dialogs ignore it.
      2. D-Bus (logind/org.freedesktop.login1)

        • Acquired inhibitor locks via D-Bus using Inhibit() on org.freedesktop.login1.Manager.
        • Successfully prevents terminal shutdowns, but again, GUI shutdown is unaffected.
      3. GNOME Session Manager

        • Explored using org.gnome.SessionManager’s Inhibit() method.
        • It works only on GNOME, not across other DEs like KDE or XFCE.

      The requirement:

      • Must be non-root, i.e., work in user space.
      • Must not require modifying system-level files, polkit rules, or shutdown scripts.
      • Should work across multiple desktop environments if possible.
      • Goal is to inform or prevent shutdown temporarily during a critical operation, then release the block once done.

      Questions:

      • Is there a Qt-native or Qt-compatible way to block or delay system shutdown while a long-running task is active?
      • Are there any Qt APIs or DBus wrappers you recommend for this use case?
      J Offline
      J Offline
      JonB
      wrote on 4 Apr 2025, 11:09 last edited by
      #2

      @Ghost-Uchiha said in How can I block or delay system shutdown in Linux using a Qt (PySide6) application?:

      Is there a Qt-native or Qt-compatible way to block or delay system shutdown while a long-running task is active?

      No, nothing to do with Qt.

      If you can even do this, and you require non-root, plus no system file alterations, it would not surprise me if you needed to communicate a request from your user app to, say, a root privilege app.

      G 1 Reply Last reply 4 Apr 2025, 11:17
      0
      • J JonB
        4 Apr 2025, 11:09

        @Ghost-Uchiha said in How can I block or delay system shutdown in Linux using a Qt (PySide6) application?:

        Is there a Qt-native or Qt-compatible way to block or delay system shutdown while a long-running task is active?

        No, nothing to do with Qt.

        If you can even do this, and you require non-root, plus no system file alterations, it would not surprise me if you needed to communicate a request from your user app to, say, a root privilege app.

        G Offline
        G Offline
        Ghost-Uchiha
        wrote on 4 Apr 2025, 11:17 last edited by
        #3

        @JonB
        Thank you for the clarification — that makes sense. I agree this is more of a system/desktop-level concern than something Qt directly handles.

        I’m trying to avoid root privileges or installing any privileged helpers since the app is intended to be open source and portable across desktop environments.

        So far I’ve had partial success using:

        • systemd-inhibit
        • D-Bus with org.freedesktop.login1
        • GNOME Session Manager’s Inhibit() method

        But none of these seem to reliably prevent GUI shutdowns across desktops. If there's a way to register my app with the session manager or logind in a way that the DE respects (without requiring Polkit modification), I'd love to hear about it.

        Appreciate the insight!

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 4 Apr 2025, 19:01 last edited by
          #4

          Hi and welcome to devnet,

          I think that you are looking for QGuiApplication::commitDataRequest.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          G 1 Reply Last reply 7 Apr 2025, 06:25
          1
          • S SGaist
            4 Apr 2025, 19:01

            Hi and welcome to devnet,

            I think that you are looking for QGuiApplication::commitDataRequest.

            G Offline
            G Offline
            Ghost-Uchiha
            wrote on 7 Apr 2025, 06:25 last edited by
            #5

            @SGaist
            Thanks for the suggestion! I’ll definitely try using commitDataRequest().

            Just to clarify — will this method reliably block or cancel GUI-initiated shutdowns (like using the power-off button from GNOME or KDE) if I call manager.cancel() inside that slot?

            Also, does this approach still work reliably with modern session managers, given that some DEs (like GNOME) are moving away from traditional X11 session management?

            Are there any best practices for using commitDataRequest() together with D-Bus inhibitors or org.freedesktop.login1 to improve compatibility across desktop environments?

            Thanks again — I appreciate your insights!

            1 Reply Last reply
            0

            2/5

            4 Apr 2025, 11:09

            • Login

            • Login or register to search.
            2 out of 5
            • First post
              2/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved