Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

You will have many recoverable tape errors.


devel / comp.lang.python / Re: Receive a signal when waking or suspending?

SubjectAuthor
o Re: Receive a signal when waking or suspending?Skip Montanaro

1
Re: Receive a signal when waking or suspending?

<mailman.252.1650903710.20749.python-list@python.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18036&group=comp.lang.python#18036

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: skip.mon...@gmail.com (Skip Montanaro)
Newsgroups: comp.lang.python
Subject: Re: Receive a signal when waking or suspending?
Date: Mon, 25 Apr 2022 11:21:22 -0500
Lines: 69
Message-ID: <mailman.252.1650903710.20749.python-list@python.org>
References: <CANc-5UwhT5xKF0azhhQ6DS=QK6awRz-HXnEfo8fUPbwi-+bNEg@mail.gmail.com>
<7a911f9e-9c85-05b3-02f4-ddf877ddb75d@DancesWithMice.info>
<CANc-5UyvVBH+Njk1Zwj22iASvQntJTH2mqTWC=XzenKH7F7cZg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de rjhCF4sCgHrT7gj7GMHoAAWG83uxYTm2BihwcI3YIe3w==
Return-Path: <skip.montanaro@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=Kh+jJbNt;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.033
X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'looks': 0.02; 'url-
ip:140.82/16': 0.03; 'stream': 0.04; 'subject:when': 0.07;
'url:status': 0.07; ':-)': 0.09; 'apparently': 0.09; 'binaries':
0.09; 'cc:addr:python-list': 0.09; 'pre': 0.09; 'routine': 0.09;
'url:master': 0.09; '&gt;': 0.14; 'url:github': 0.14; 'url-
ip:140/8': 0.15; '(*)': 0.16; "(i'm": 0.16; '0644': 0.16;
'arguments': 0.16; 'bits': 0.16; 'cat': 0.16; 'cc:name:python':
0.16; 'installed.': 0.16; 'missed': 0.16; 'psutil': 0.16;
'url:time': 0.16; 'values': 0.17; 'applications': 0.17; "can't":
0.17; 'cc:addr:python.org': 0.20; 'machine': 0.22; "i've": 0.22;
'maybe': 0.22; '\xe2\x80\x94': 0.22; 'installed': 0.23; 'run':
0.23; 'anything': 0.25; 'skip:- 10': 0.25; 'help.': 0.25;
'cc:2**0': 0.25; 'library': 0.26; 'leave': 0.27; 'local': 0.27;
'bit': 0.27; 'example,': 0.28; 'ideas': 0.28; 'seem': 0.31;
'think': 0.32; "doesn't": 0.32; 'dropped': 0.32; 'fine.': 0.32;
'message-id:@mail.gmail.com': 0.32; 'but': 0.32; "i'm": 0.33;
"i'll": 0.33; 'script': 0.33; "didn't": 0.34; 'header:In-Reply-
To:1': 0.34; 'received:google.com': 0.34; 'skip:2 20': 0.35;
'track': 0.35; 'from:addr:gmail.com': 0.35; 'change': 0.36;
'couple': 0.37; "skip:' 10": 0.37; 'received:209.85': 0.37;
'file': 0.38; 'way': 0.38; 'could': 0.38; 'received:209': 0.39;
'changes': 0.39; 'enough': 0.39; 'handle': 0.39; 'use': 0.39;
'rest': 0.39; 'want': 0.40; 'should': 0.40; 'url:amp': 0.62;
'gives': 0.62; 'subject': 0.63; 'bringing': 0.64; 'skip:r 40':
0.64; 'thus': 0.64; 'url:watch': 0.64; 'your': 0.64; 'tool': 0.65;
'pay': 0.65; 'time.': 0.66; 'url:q': 0.67; 'further': 0.69;
'relate': 0.69; 'skip:/ 10': 0.69; 'skip:/ 30': 0.69; 'times':
0.69; 'took': 0.69; 'url-ip:lookup error': 0.70; 'solutions':
0.70; 'attention': 0.71; 'url:t': 0.73; 'man': 0.74; 'records':
0.75; 'monitor': 0.81; 'period': 0.81; '(like': 0.84; 'so:': 0.84;
'suspend': 0.84; 'url:src': 0.84; 'react': 0.91; 'resting': 0.91;
'resume,': 0.91; 'battery': 0.93; 'url-ip:2.19.194/24': 0.93;
'url-ip:2.19/16': 0.93; 'url-ip:92/8': 0.93; 'url-ip:2/8': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=vT4CDhOHJFf1pDSuIEL8bu20ujb8cttddGabIp5oYmc=;
b=Kh+jJbNtWkvFUdPlSr4JEqQaoYWbtQshcH05CVrBsCetJYjRd7g3HV7918TTKM/s1w
y33+jsPXvaXClF3RBlC/6TkEte9EiHr3iCrH6WoSfrVX0joMjx+bV6ioo3GjXzmS9Snt
s/Ma6/P8p4Pg6KHsMZVRcEV4BtWCc7oHfFcCGZ5Y/KXSM+p+tQoQZIrlDceX2mJtqn0u
Wb6DUEfFD8AG2AYtpr03gDA2brmAUc6IyQkCLzCUVcS6oAjUdZnW9x2q3Hp6SdQQpfls
dmAv6sThBrMw05uuSFmp/eFu/yCZ4+jvEjggxpAquEjCD8OLme56eA225hAOlfFy0kdW
klLQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=vT4CDhOHJFf1pDSuIEL8bu20ujb8cttddGabIp5oYmc=;
b=E4pHvdGCv4razwnFIZpEiRPXn+SxmLScJfAOJ8I3zE1PhD4sxC1gJ5oXWStQ0I6LI0
qsVicyPcIJALlOukrtqEnTvJFARkbAjO2QzNYnx/6lonHGjFF1FWlb4NziWL33UdoeBL
IdYJoRF1E2QreqJCy3m6mh3w+dIApegs7JMyO9o2SeUjWRQdNOxt68qmxoZkdHRg0/tp
LpPonftlI5u9G9vdvNa7nMmQxS2sAiCEYFj/qzgLQmBNd/lbVzIvHp56U9VCc7a5+OWq
PGQAhKtbYBOUi1hIqAFYkHBY5RMCdv0VcSw1WpY0E3Pk6xl6c4md7KCR82f+OQ+ktElw
/xuQ==
X-Gm-Message-State: AOAM533LMS+5Qc/z4hC83WeicN1VKnBdtoKjHq1N6nzAC3816zSgvi7Q
d7Ev1xNEBGLytHaT7YlU5xYua83r1RNXHAB3PS4N84T+XdBCPhA=
X-Google-Smtp-Source: ABdhPJwSviHUqWbbjsg51BhOwyokQuS1wdplBrlTHhImbm677WRGoTmIR3iewQqZJtzE7IzqUiidGBgCIsy1J4E+mwU=
X-Received: by 2002:a81:3dc6:0:b0:2f8:f29:b429 with SMTP id
k189-20020a813dc6000000b002f80f29b429mr1355092ywa.393.1650903707770; Mon, 25
Apr 2022 09:21:47 -0700 (PDT)
In-Reply-To: <7a911f9e-9c85-05b3-02f4-ddf877ddb75d@DancesWithMice.info>
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CANc-5UyvVBH+Njk1Zwj22iASvQntJTH2mqTWC=XzenKH7F7cZg@mail.gmail.com>
X-Mailman-Original-References: <CANc-5UwhT5xKF0azhhQ6DS=QK6awRz-HXnEfo8fUPbwi-+bNEg@mail.gmail.com>
<7a911f9e-9c85-05b3-02f4-ddf877ddb75d@DancesWithMice.info>
 by: Skip Montanaro - Mon, 25 Apr 2022 16:21 UTC

> https://duckduckgo.com/?t=ffab&q=python+up+time pointed-out the
> "uptime — Cross-platform uptime library"
> - TLDR; I'm not sure if "uptime" and "boot" relate only to a
> 'cold-start' or if they include bringing the machine out of 'stand-by'
> or 'hibernation'

Yeah, that won't help. uptime(1) gives the time since the last boot.
Wake/suspend doesn't change the system's notion of boot time.

> https://duckduckgo.com/?t=ffab&q=python+battery+status pointed-out
> several ideas which require MS-Windows, but apparently the psutil
> library could be bent to your will:
>
https://www.geeksforgeeks.org/python-script-to-shows-laptop-battery-percentage/

I actually already have psutil installed. It gives you details about
various system bits (like battery status, which is why I installed it). It
doesn't seem to have anything that will notify about state changes, just
the current state (or — for example — continuous values like the battery
state of charge). I didn't see anything regarding wake/suspend, but I might
have missed it. Since my tool can't run while the system is suspended, it
would always see the system as "awake" but not know for how long it was in
that state. (I'm sure I could track in my tick routine and pay attention to
unusually long gaps.)

I think Marco's response gives me a bit better handle on what I need(*). Maybe
just an easier way to do things. For example, just before suspending and
just after waking, all scripts in /usr/lib/systemd/system-sleep/ are
executed. The only difference is the arguments with which they are called.
A script to suit my needs can just write a stream of records with
timestamps. It took just a minute or so:

#!/bin/sh

echo "`date --iso-8601=seconds` $1 $2" >> /tmp/suspensions
chmod 0644 /tmp/suspensions

Here's what /tmp/suspensions looks like after a couple cycles:

root@montanaro:/usr/lib/systemd/system-sleep# cat /tmp/suspensions
2022-04-23T19:17:41-05:00 pre suspend
2022-04-23T19:17:54-05:00 post suspend
2022-04-23T19:18:48-05:00 pre suspend
2022-04-23T19:19:04-05:00 post suspend

My tool can monitor that file for changes and keep track of the times of
state changes. It can thus track rest intervals across system suspensions
and know if I've been resting for a long enough period of time to allow me
to subject my wrists to further agony
<https://github.com/smontanaro/python-bits/blob/master/src/watch.py> with
the keyboard and mouse.

Skip

(*) man systemd-sleep contains this admonition:

Note that scripts or binaries dropped in /lib/systemd/system-sleep/ are
intended for local use only and *should be considered hacks*. If
applications want to react to system suspend/hibernation and resume,
they should
rather use the Inhibitor interface[1].

A hack should suit my needs just fine. I'll leave more elegant solutions to
others. :-)

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor