{"id":18770046,"url":"https://github.com/yaroslaff/lightsleep","last_synced_at":"2026-05-06T03:31:17.823Z","repository":{"id":62576104,"uuid":"455320267","full_name":"yaroslaff/lightsleep","owner":"yaroslaff","description":"sleep() you can interrupt with redis or websocket event","archived":false,"fork":false,"pushed_at":"2022-05-18T16:54:18.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-27T18:34:13.718Z","etag":null,"topics":["cron","cronjob","instant","interrupt","interruption","redis","safe","sleep","websocket"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yaroslaff.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-03T20:38:00.000Z","updated_at":"2022-02-05T19:54:57.000Z","dependencies_parsed_at":"2022-11-03T18:54:40.506Z","dependency_job_id":null,"html_url":"https://github.com/yaroslaff/lightsleep","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yaroslaff/lightsleep","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaroslaff%2Flightsleep","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaroslaff%2Flightsleep/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaroslaff%2Flightsleep/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaroslaff%2Flightsleep/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yaroslaff","download_url":"https://codeload.github.com/yaroslaff/lightsleep/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaroslaff%2Flightsleep/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32677860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-06T02:33:58.958Z","status":"ssl_error","status_checked_at":"2026-05-06T02:33:39.611Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cron","cronjob","instant","interrupt","interruption","redis","safe","sleep","websocket"],"created_at":"2024-11-07T19:17:54.492Z","updated_at":"2026-05-06T03:31:17.790Z","avatar_url":"https://github.com/yaroslaff.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lightsleep\nLightsleep is sleep() you can interrupt with redis or websocket event or touch/write file.\n\nThis is nice feature if you want to do some actions periodically AND immediately on some event.\n\n# Install\n\nInstall from pypi:\n~~~\npip3 install lightsleep\n~~~\n... or install from git:\n~~~\npip3 install git+https://github.com/yaroslaff/lightsleep\n~~~\n\n\n## lsleep \n`lsleep.py` is very short simple CLI utility (better then `/usr/bin/sleep`) which is also demo how to use `lightsleep` python module.\n\nAlmost useless example where lsleep is identical to `/usr/bin/sleep` (sleep 60 seconds):\n~~~\nlsleep.py 60\n~~~\n\nEven 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`. \n\nIf `-t`/`--title` set, lsleep.py will use setproctitle. So, you may call `lsleep.py 600 -t mysleep` and then `killall mysleep` to stop only this lsleep process. \n\n`lsleep.py -h` will list all available hooks and their default options\n\n### Interrupt sleep with touch or any write\n~~~\nlsleep.py 300 --hook mtime path=/tmp/x\n~~~\n\nYou can interrupt sleep with `touch /tmp/x` or `echo anything \u003e /tmp/x`.\n\n\n### interrupt sleep with redis PUBLISH command\n\n`lsleep.py 60 --hook redis` (defaults: local redis server, channel `sleep`)\n\nInterrupt this sleep from redis-cli:\n~~~\n127.0.0.1:6379\u003e PUBLISH sleep anything\n(integer) 1\n~~~\n\nTo override defaults parameters: \n~~~\nlsleep.py 60 --hook redis url=redis://localhost:6379/0 msg=stop ch=sleep\n~~~\n(seting `msg` to any value will requre to PUBLISH exact this value. If `msg` is not set, any message will interrupt sleep)\n\n### Interrupt sleep with websocket \n~~~\nlsleep.py 300 --hook ws url=http://localhost:8899/ room=myapps::u1 secret=myapps-pass\n~~~\n\nYou may use [ws-emit](https://github.com/yaroslaff/ws-emit) websocket application as server.\n\noptional `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`\n\nIf `event` and `data` specified, sleep will be interrupted only if websocket event name and data matches it.\n\n## Using sleep in your package\nSee lsleep.py code, it's very small. Example:\n\n~~~python\nfrom lightsleep import Sleep\n\ns = Sleep(hook=['redis','msg=stop', 'ch=sleep'])\ns.sleep(60)\n~~~\n\n`sleep()` returns message which interrupted sleep (if hook supports this). For example, if redis hook used and sleep was interrupted with `PUBLISH sleep zzz`, `sleep()` will return `zzz`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaroslaff%2Flightsleep","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyaroslaff%2Flightsleep","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaroslaff%2Flightsleep/lists"}