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.3.3.tar.gz
(2.2 kB
view details)
Built Distribution
File details
Details for the file lazy_main-0.3.3.tar.gz
.
File metadata
- Download URL: lazy_main-0.3.3.tar.gz
- Upload date:
- Size: 2.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.8.10 Linux/5.15.0-116-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e64ac0e43e4f1504d657e90f69899004c334529231f3e67686eba65e291aba6 |
|
MD5 | d791a113d14002361cf6d3307ec11b9d |
|
BLAKE2b-256 | f43a68205ce40559d0e7c84b8ed4439746f8ada3369ce6abe54ae14018428cd2 |
File details
Details for the file lazy_main-0.3.3-py3-none-any.whl
.
File metadata
- Download URL: lazy_main-0.3.3-py3-none-any.whl
- Upload date:
- Size: 2.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.8.10 Linux/5.15.0-116-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22f2160cddaaba0300eeeb7a1c3b85a0a979dead88e722a06cc3f4b76b6603c3 |
|
MD5 | fc74874af41bd26880a0fe3e163cf865 |
|
BLAKE2b-256 | c2257feecc1ca2d07cac4779b72e339d33a23577480349f3486c6908542d596f |