Tuesday, May 14, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 2007  / 3 Years ago, fri, july 2, 2021, 11:20:17

Say you have a DBus service on the session bus (the per-user bus). Your service might get started via an /etc/xdg/autostart/* file, or it might get started the first time some app tries to use your well-known service name. Either way, let's say that the DBus session bus is the process that starts your service.



And then the user logs out. So what happens? Does DBus send any actionable SIG<foo> signals to your service, or is it strait to SIGKILL? Is there any other way to know the user is logging out? Basically, I have some cleanup actions I need to run, which includes killing sub-processes started with subprocess.Popen and multiprocessing.



Now you before you say, "Popen and multiprocessing are evil, don't use them", in my current experiment, I'm not using them. I'm just trying to figure out how a Python DBus service can hook into something that allows it to run cleanup actions, whatever the overall architecture might be.



Any advice? Any examples? Note that my example will be running in a GObject.MainLoop and is using Python3 on Ubuntu Precise (or Quantal).


More From » python

 Answers
1

You can either do something like this:



bus = dbus.SessionBus()
bus.call_on_disconnection(your_method_to_do_stuff)


Or you can connect to the NameLost signal on the org.FreeDesktop.DBus interface. The former doesn't let you pass additional arguments, and your method can only take the bus connection object itself as an argument. The latter is a bit more complicated, but doesn't seem to allow passing in other arguments of your own accord either, and you are limited to taking the arguments which the signal itself sends, which in this case is a string of the message bus name your process formerly owned.



On the other hand, if your process does stay around after that, you should theoretically get a SIGKILL at some point as well.


[#36866] Saturday, July 3, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
impisaso

Total Points: 423
Total Questions: 106
Total Answers: 104

Location: Virgin Islands (U.S.)
Member since Tue, Feb 2, 2021
3 Years ago
;