Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
wake_event.set()
update_loop_task = None
def prepare_for_sleep(sleep):
if sleep:
logging.info("Preparing for sleep")
wake_event.clear()
if update_loop_task:
update_loop_task.cancel()
else:
wake_event.set()
logging.info("Woke up")
_, dbus_proto = await jeepney.integrate.asyncio.connect_and_authenticate('SYSTEM')
dbus_bus = jeepney.integrate.asyncio.Proxy(jeepney.bus_messages.message_bus, dbus_proto)
dbus_proto.router.subscribe_signal(
callback=lambda args: prepare_for_sleep(*args),
path='/org/freedesktop/login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep'
)
await dbus_bus.AddMatch(jeepney.bus_messages.MatchRule(
type='signal',
sender='org.freedesktop.login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep',
path='/org/freedesktop/login1'
))
wake_event.set()
update_loop_task = None
def prepare_for_sleep(sleep):
if sleep:
logging.info("Preparing for sleep")
wake_event.clear()
if update_loop_task:
update_loop_task.cancel()
else:
wake_event.set()
logging.info("Woke up")
_, dbus_proto = await jeepney.integrate.asyncio.connect_and_authenticate('SYSTEM')
dbus_bus = jeepney.integrate.asyncio.Proxy(jeepney.bus_messages.message_bus, dbus_proto)
dbus_proto.router.subscribe_signal(
callback=lambda args: prepare_for_sleep(*args),
path='/org/freedesktop/login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep'
)
await dbus_bus.AddMatch(jeepney.bus_messages.MatchRule(
type='signal',
sender='org.freedesktop.login1',
interface='org.freedesktop.login1.Manager',
member='PrepareForSleep',
path='/org/freedesktop/login1'
))