Skip to main content

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


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.2.tar.gz (2.2 kB view details)

Uploaded Source

Built Distribution

lazy_main-0.3.2-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file lazy_main-0.3.2.tar.gz.

File metadata

  • Download URL: lazy_main-0.3.2.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

Hashes for lazy_main-0.3.2.tar.gz
Algorithm Hash digest
SHA256 3ad385d49ea5f163949074515a1d03fbe78e04dfeab9b78dbc38b12e52a5e2e9
MD5 28dccd008d6797a6fbb429511e89fa8e
BLAKE2b-256 cea8bf4386d4047bf4a1eae436e56073f9099601d66301b3ac4fd0d3290f1315

See more details on using hashes here.

File details

Details for the file lazy_main-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: lazy_main-0.3.2-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

Hashes for lazy_main-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0d36e13e1e103332df464bbb7513590c949a53d6621a910eeaf36acb6fe1f928
MD5 5bd686848561fc9830d983ae18845b88
BLAKE2b-256 45c5529e6511e9d0085e4492dfaf711707088585460d7d90f121fb0642285fb4

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