No project description provided
Project description
lazy-main
Generalized framework for main loop function.
Installation
pip install lazy-main
How to Use
from lazy_main import LazyMain
def main(*args, **kwargs):
print("Hello World!")
def error_handler(exception):
print("An error occurred!", exception)
if __name__ == "__main__":
LazyMain(
main=main,
error_handler=error_handler, # This is optional.
sleep_min=3,
sleep_max=5,
print_logs=True,
loop_count=-1, # -1 Means it will loop infinitely.
).run()
You can also pass arguments to the main
function.
from lazy_main import LazyMain
def main(*args, **kwargs):
print(kwargs["hello"]) # World!
if __name__ == "__main__":
LazyMain(
main=main,
).run(
hello="World!",
)
Returning True
will print the total elapsed time.
from lazy_main import LazyMain
def main():
return True
if __name__ == "__main__":
LazyMain(
main=main,
).run() # Done in 0.10s.
Returning SIGTERM
will terminate the loop.
from lazy_main import LazyMain
import signal
def main():
return signal.SIGTERM
if __name__ == "__main__":
LazyMain(
main=main,
).run()
print("I'm free!")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lazy_main-0.4.2.tar.gz
(2.5 kB
view details)
Built Distribution
File details
Details for the file lazy_main-0.4.2.tar.gz
.
File metadata
- Download URL: lazy_main-0.4.2.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.8.10 Linux/5.15.0-117-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 899560617b2fc3e7ef3c9f80a30cdc7de872545639f7e953ee461adf46a09350 |
|
MD5 | 819949415f224bbdccd0187b4bc70c46 |
|
BLAKE2b-256 | 9cbd9217792069a1437d88284ce3af34528f1df6199f697a9cca0b70c25d17d5 |
File details
Details for the file lazy_main-0.4.2-py3-none-any.whl
.
File metadata
- Download URL: lazy_main-0.4.2-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.8.10 Linux/5.15.0-117-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfb5ace71c5f9320adeafb32afe3da31313b3362f132e9cae459091978002df3 |
|
MD5 | c33ae0e7412e5ad43007eba87f2b36ea |
|
BLAKE2b-256 | 973fc2d0ad96d442917fdf1731eaefa8939e24beaa2daf83a2bf19fb413065b2 |