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()
Some aliases are also provided for loop_count.
...
LazyMain(
...
# Sets `loop_count` to 1 if `True`.
# Sets `loop_count` to -1 if `False`.
# Does nothing if `None`.
run_once=True,
...
)
# Or...
LazyMain(
...
# Sets `loop_count` to -1 if `True`.
# Sets `loop_count` to 1 if `False`.
# Does nothing if `None`.
run_forever=True,
...
)
...
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.
If you don't like the logs, you can disable it.
from lazy_main import LazyMain
...
if __name__ == "__main__":
LazyMain(
...
print_logs=False,
...
).run()
...
Returning Terminate will terminate the loop.
from lazy_main import LazyMain, Terminate
def main():
return Terminate
if __name__ == "__main__":
LazyMain(
main=main,
).run()
print("I'm free!")
You can also use a generator for the return value.
from lazy_main import LazyMain, Terminate
def main():
for i in range(10):
if i == 5:
yield Terminate
if __name__ == "__main__":
LazyMain(
main=main,
).run()
print("I'm free!")
You can also provide dynamic kwargs via iteration.
from lazy_main import LazyMain
def main(*args, **kwargs):
print(kwargs["hello"]) # 0, 1, 2, 3, ...
if __name__ == "__main__":
i = 0
for loop in LazyMain(
main=main,
):
loop(
hello=i,
)
i += 1
Metadata
Release files for lazy-main 0.6.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lazy_main-0.6.2.tar.gz | 2.8 kB | Without provenance | Details for lazy_main-0.6.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lazy_main-0.6.2-py3-none-any.whl | Python 3 | none | any | Details for lazy_main-0.6.2-py3-none-any.whl |
Total release size: 6.7 kB
Release files / lazy_main-0.6.2.tar.gz
| Download URL | lazy_main-0.6.2.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b17c90696c49b083eafe13c3a2104529083a97110dce4bfa644d66b7ade16385
|
|
BLAKE2b-256 checksum How to use checksums |
24fb4b388293e67e71d508ba3d8ee911e8928f9d8c0be3cf70511d397aa92c35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2
|
Release files / lazy_main-0.6.2-py3-none-any.whl
| Download URL | lazy_main-0.6.2-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e074dccb0925e3cbb74925e02c5f73a0743468b135c23133396d5f98f9290637
|
|
BLAKE2b-256 checksum How to use checksums |
fb8f4eff410260387e031d0903d2c401f07dc6bd66fa9673099e9e745fc8476d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2
|
Security for lazy-main 0.6.2
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.