Xfce Forum

Sub domains
 

You are not logged in.

#1 2026-08-27 23:53:13

Pheeble
Member
Registered: 2015-06-22
Posts: 34
LinuxFirefox 153.0

How to detect session logout in Python?

Linux Mint 22.1 XFCE 4.18

I have a Python script that I launch at login to perform some monitoring and logging tasks during the session.

I want it to be able to shut down gracefully when I log out.

I assumed it would be sent a SIGTERM signal at logout, so I wrote the shut down function to be run when the SIGTERM signal is received.

It works perfectly if I run the python script in a terminal and send the SIGTERM signal via a kill command, but a SIGTERM signal is never received when I log out. Presumably xfce4-session-logout does not send signals.  sad

Is there some way to detect when xfce4-session-logout is about to end the session?

Offline

#2 2026-08-28 00:06:49

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 12,680
LinuxFirefox 154.0

Re: How to detect session logout in Python?

If you go to Settings Manager > Session and Startup > Application Autostart, you can set a script to run on a logout, restart, or shutdown trigger. You can try that to see if it works.

Otherwise, you can look at creating an xfce4-session wrapper script.


Mark solved threads as [SOLVED] to make it easier for others to find solutions.
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Online

#3 2026-08-28 01:00:12

Pheeble
Member
Registered: 2015-06-22
Posts: 34
LinuxFirefox 153.0

Re: How to detect session logout in Python?

ToZ wrote:

If you go to Settings Manager > Session and Startup > Application Autostart, you can set a script to run on a logout, restart, or shutdown trigger. You can try that to see if it works.

Otherwise, you can look at creating an xfce4-session wrapper script.

Thanks for the speedy reply  smile

It looks like the easiest solution is to modify my python script to check for script arguments at launch, and simply re-launch the script with, for example, a '--shutdown' argument via the triggers you mentioned.

Do you know if there is any reliable way to detect a logout/shutdown process programmatically in XFCE, such as via dbus?

Offline

#4 2026-08-28 10:21:03

eriefisher
Wanderer
From: ON, Canada
Registered: 2008-10-25
Posts: 1,019
Website
LinuxFirefox 154.0

Re: How to detect session logout in Python?

If you put your script in the autostart list, logging out or shutting down will kill the script.


But it's all right, when you're all in pain and you feel the rain come down
It's alright, when you find your way, then you see it disappear
It's alright....
Chris Cornell

Offline

#5 2026-08-28 10:25:06

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 12,680
LinuxFirefox 154.0

Re: How to detect session logout in Python?

Pheeble wrote:

Do you know if there is any reliable way to detect a logout/shutdown process programmatically in XFCE, such as via dbus?

You could try using systemd to run a script on shutdown. See https://forum.manjaro.org/t/running-a-s … /143440/2\ for an example of how this can be done.


Mark solved threads as [SOLVED] to make it easier for others to find solutions.
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Online

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.019 seconds, 7 queries executed - Memory usage: 537.01 KiB (Peak: 537.98 KiB) ]