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

Uploaded Source

Built Distribution

lazy_main-0.4.3-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lazy_main-0.4.3.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-119-generic

File hashes

Hashes for lazy_main-0.4.3.tar.gz
Algorithm Hash digest
SHA256 3debd5a3b5a1c6ba2160275e0a738701f6deb33cba642b61d2c932a5c6da2d7b
MD5 b64d49a2db198c5139f0fb577d20dbb5
BLAKE2b-256 4fa1de5e4d7c29fb824837a03b6d85d3386263db38566bfe075a12898f6a6ea3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lazy_main-0.4.3-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-119-generic

File hashes

Hashes for lazy_main-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 32fad7635dc56f9ae5165c1eab9c45105d6cbd44d5263f0f4aea3bbb68368e64
MD5 4b3f426208a1896050675d28d51e321e
BLAKE2b-256 08dfef7530e8df58a0a8073e8f6486bf17f2eabe3a37df8826b70990b43a0241

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