Skip to main content

Python time limiter library

Project description

Welcome to timelimiter

Version Python License: MIT

Python time limiter library.

Beyond a certain wait interval, a successful result is unlikely.

Resources:

Usage

  1. Extend TimeoutHandler with timeout expressed in seconds。Override _run method。MySQLTimeoutHandler for example.
from timelimiter.timeout_handler import TimeoutHandler, TimeoutHandlerFactory


class MySQLTimeoutHandler(TimeoutHandler):
    timeout = 0.5

    def __init__(self):
        super(MySQLTimeoutHandler, self).__init__()
        # Some way to get MySQL thread id
        self.thread_id = 1

    def _run(self):
        # Kill MySQL connection
        print(self.thread_id)


class MySQLTimeoutHandlerFactory(TimeoutHandlerFactory):
    def create_handler(self) -> TimeoutHandler:
        return MySQLTimeoutHandler()
  1. Use TimeLimiter to wrap the function。
from timelimiter.event_loop import start_loop
from timelimiter.time_limiter import TimeLimiter

start_loop()
factory = MySQLTimeoutHandlerFactory()

@TimeLimiter(factory)
def foo():
    # Do something
    ...

Configuration

Use environment to set configuration.

Name Description Default
TIME_LIMITER_CAPACITY Max capacity for time limiter queue 100,000

Author

👤 Keyes Hsu

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2022 Keyes Hsu.
This project is MIT licensed.


This README was generated with ❤️ by readme-md-generator

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

timelimiter-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

timelimiter-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file timelimiter-0.1.0.tar.gz.

File metadata

  • Download URL: timelimiter-0.1.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.10

File hashes

Hashes for timelimiter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2f9b1b860dd7c263c46b290a091a523e25ca8468c4ee79b511b1cd83599bd3be
MD5 afec50df1429b281f139a3e8f15cf652
BLAKE2b-256 6abf9a88fb2e4a6221e041f022ec5303d8442b01edde4ca439f6e0a505d21f15

See more details on using hashes here.

File details

Details for the file timelimiter-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: timelimiter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.10

File hashes

Hashes for timelimiter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd4852c1ba3339703308670c7b7620f0104e53d3b3b5d7eba007c647100e80e8
MD5 340b5eb289ceaa89ea54e5f08fd2cd5c
BLAKE2b-256 3777edb48bcc4aab46490a54c61586d7736e03f1642b3c0bff89ad995bc86920

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