How can I catch a system suspend event in Python?

events, linux, python, suspend, ubuntu

Solution

i think simplest method would be to use DBUS python interface and listen for 'AboutToSleep' and/or 'Sleeping' event on 'org.freedesktop.UPower' interface

Problem

I'm using ubuntu 12.04. Is there a way to catch a suspend event in Python, i.e. if the laptop is going to suspend, do this...? The same question for catching shutdown event.

Original source

Related problems