Skip to main content

sleep() you can interrupt with redis or websocket event

Project description

lightsleep

Lightsleep is sleep() you can interrupt with redis or websocket event

This is nice feature if you want to do some actions periodically AND immediately on some event.

Install

Install from pypi:

pip3 install lightsleep

... or install from git:

pip3 install git+https://github.com/yaroslaff/lightsleep

lsleep

lsleep.py is very short simple CLI utility (better then /usr/bin/sleep) which is also demo how to use sleep.

Almost useless example where lsleep is identical to /usr/bin/sleep (sleep 60 seconds):

lsleep.py 60

Even this example has some benefits - if your program will run external program lsleep.py instead of sleep(), you can always send kill to lsleep (e.g. with killall lsleep.py) and this is much more reliable then interrupting sleep() inside program. But thats same as /usr/bin/sleep. See below for more useful examples.

lsleep.py -h will list all available hooks and their default options

interrupt sleep with redis PUBLISH command

lsleep.py 60 --hook redis (defaults: local redis server, channel sleep)

Interrupt this sleep from redis-cli:

127.0.0.1:6379> PUBLISH sleep anything
(integer) 1

To override defaults parameters:

lsleep.py 60 --hook redis url=redis://localhost:6379/0 msg=stop ch=sleep

(seting msg to any value will requre to PUBLISH exact this value. If msg is not set, any message will interrupt sleep)

Interrupt sleep with websocket

lsleep.py 300 --hook ws url=http://localhost:8899/ room=myapps::u1 secret=myapps-pass

You may use ws-emit websocket application as server.

optional secret if room requires secret to join (when room name containts '::'). This should match ws-emit secret in redis, set with SET ws-emit::secret::myapps myapps-pass

If event and data specified, sleep will be interrupted only if websocket event name and data matches it.

Using sleep in your package

See lsleep.py code, it's very small. Example:

from lightsleep import Sleep

s = Sleep(hook=['redis','msg=stop', 'ch=sleep'])
s.sleep(60)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

lightsleep-0.0.1.post1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file lightsleep-0.0.1.post1-py3-none-any.whl.

File metadata

  • Download URL: lightsleep-0.0.1.post1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.2

File hashes

Hashes for lightsleep-0.0.1.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 521c445ef7e95016bf679e66c24abc607fc607bbd6f9a63f06b63c1a33e448cb
MD5 53a2de2c55b782aa8845fd4db4f399a0
BLAKE2b-256 3d4b9b04ab58a664f650c3d1508d5e9b0fe6d125a42062eb3a7ce9f8db3b834e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page