Skip to main content

Simple polling-style loop running in separate thread

Project description

Quick Looper

A simple polling style loop, run in a separate thread.

Installation

Install from PyPI:

pip install quicklooper

How to use

Make a class that inherits from the Looper class, and override the main method with code to be run each loop. The loop period may be set by assigning a float value to the class variable _interval or by passing the interval keyword arg to the Looper.__init__ method.

Override the on_start_up and on_shut_down methods to add any code to be run before the first loop, and after the final loop when stop is called.

Example of a basic app which polls the /printfiles directory for new files to print:

from quicklooper import Looper


class PrintMonitor(Looper):
    _interval = 10.0

    def __init__(self, directory: str):
        self.directory: str = directory
        self._printed_files: Set[str] = set()

    def on_start_up():
        self._printed_files = {file for file in os.listdir(self.directory)}

    def main():
        for file in os.listdir(self.directory):
            send_to_printer(file)  # implementation not shown
            self._printed_files.add(file)


if __name__ == '__main__':
    print_monitor = PrintMonitor('/printfiles')
    print_monitor.start()

When print_montitor.start() is called, the app runs on_start_up method, and then calls main every ten seconds to scan for new files to print.

Call stop to exit the loop immediately.

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

quicklooper-1.0.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

quicklooper-1.0.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file quicklooper-1.0.0.tar.gz.

File metadata

  • Download URL: quicklooper-1.0.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1

File hashes

Hashes for quicklooper-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d8259bff7af8603d7b47343a3f204650bf9c60e67420a8f371013cb9f5aa4096
MD5 0f313760581adeb6be2bc85aac7bec0d
BLAKE2b-256 87f5c70966faba51cf98aa89b0a48bb34c58e90498997dba29d14d9dcc2b8fbc

See more details on using hashes here.

File details

Details for the file quicklooper-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: quicklooper-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1

File hashes

Hashes for quicklooper-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2e71faddaffa09b66e78402b382b8193de7c8c3823335da407a0c5eaaa46c17
MD5 79870149e108b5641d6c64c752432bdf
BLAKE2b-256 2d62239fce41b06534bfdfc95aa4144fdcb16e92af5865ef7e6d01902216b04c

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