Skip to main content

Python time limiter library

Project description

Welcome to timelimiter

PyPI Python License: MIT codecov Tests

Python time limit library, using event loop to schedule job.

Resources:

Install

pip install timelimiter

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

Run tests

make test

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.1.tar.gz (7.4 kB view hashes)

Uploaded Source

Built Distribution

timelimiter-0.1.1-py3-none-any.whl (7.4 kB view hashes)

Uploaded Python 3

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