Daemon Loop
Daemon loop is simple and clean CLI utility to run programs periodically.
It's better alternative to running commands like:
while true; do date >> date.log; sleep 5; done
(or even running such commands in screen/tmux sessions)
Installation
pip3 install daemon-loop
Usage
usage: loop [-h] [-n N] [-p PERIOD] [--log FILENAME] [-e] [-v] [-d]
command [command ...]
Run command in loop (with features)
positional arguments:
command command with arguments
optional arguments:
-h, --help show this help message and exit
-n N Run N times and exit (default: 0 = infinite)
-p PERIOD, --period PERIOD
Run every N seconds (default: 60)
--log FILENAME Write command stdout to this file
-e, --err Write command stderr to logfile)
-v, --verbose Write loop technical info to logfile)
-d, --daemon Work as daemon
Example usage
Simple and almost useless - run date every second until Ctrl-C:
$ loop date
Sun Dec 20 05:18:21 +07 2020
Sun Dec 20 05:19:21 +07 2020
Sun Dec 20 05:20:21 +07 2020
^C
Run date +%s (print unixtime) 3 times every 10 seconds and quit
$ loop -p 10 -n 3 -- date +%s
1608416485
1608416495
1608416505
And now something more useful - make our date program a daemon!
$ loop -dvep 10 --log /tmp/loop.log -- date +%s
$ pidof -x loop
25934
-d: run as daemon-v: include technical info about time of start/stop, status code and daemon pid-e(--err): include stderr to logfile-p(--period): period is 10 seconds--log: logfile
log file will look like this:
# 2020-12-20 05:39:01 my pid: 25934 run: date +%s
1608417541
# 2020-12-20 05:39:01 finished with status 0
# 2020-12-20 05:39:11 my pid: 25934 run: date +%s
1608417551
# 2020-12-20 05:39:11 finished with status 0
Caveats
If --daemon used, loop will chdir to '/'. Loop will automatically adjust path to logfile and executable, but you should care about other parameters. For example, command loop -d -- touch myfile started from user home will touch /myfile (in root), and most likely will fail.
Metadata
Release files for daemon-loop 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| daemon_loop-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Release files / daemon_loop-0.0.3-py3-none-any.whl
| Download URL | daemon_loop-0.0.3-py3-none-any.whl |
|---|---|
| Size | 3.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
927a5093718abe65d85049fdcbc9733c730c4a00bb41c5c868357216da91881b
|
|
BLAKE2b-256 checksum How to use checksums |
00e4f2d3e492ed1ad1c102669b8569e6beb31c461e1745114a6d77fea1cb6fe4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.3
|
Security for daemon-loop 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.