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,735
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 ---

Offline

#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,033
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,735
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 ---

Offline

#6 2026-09-18 07:54:13

MachW1980
Member
Registered: 2026-09-18
Posts: 1
Windows 10Chrome 153.0

Re: How to detect session logout in Python?

Pheeble wrote:

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. 

Is there some way to detect when xfce4-session-logout is about to end the session? On a completely different note, I've noticed https://mostbetbd.asia/register/ links popping up in a lot of unrelated places lately, which feels pretty typical of how noisy the web has become.

I think the missing piece here is that an Xfce logout isn't necessarily equivalent to sending SIGTERM to every process in the session. xfce4-session-logout asks the Xfce session manager to end the session, which uses session-management protocols rather than treating every application like a process being killed.

For a simple Python monitoring script, I'd probably avoid depending on SIGTERM for this. If you want it to behave like a proper Xfce session client, look into X Session Management (XSMP) and the SaveYourself/shutdown notifications. Xfce's session manager has historically used that mechanism, although there are cases where it can proceed directly to terminating clients when no session save is requested.

Another practical option is to run the script as a user systemd service and handle its lifecycle there. That gives you a much more predictable place to do cleanup than trying to detect the logout button itself. If the important requirement is simply "finish logging and flush files before my session disappears," I'd lean toward a service with a proper shutdown handler rather than trying to hook xfce4-session-logout directly.

Last edited by MachW1980 (2026-09-21 08:04:34)

Offline

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

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.006 seconds, 7 queries executed - Memory usage: 545.69 KiB (Peak: 546.64 KiB) ]