Python time limiter library
Project description
Welcome to timelimiter
Python time limit library, using event loop to schedule job.
Resources:
Install
pip install timelimiter
Usage
- Extend
TimeoutHandler
withtimeout
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()
- 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
- Github: @KeyesHsu
🤝 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
Release history Release notifications | RSS feed
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 details)
Built Distribution
File details
Details for the file timelimiter-0.1.1.tar.gz
.
File metadata
- Download URL: timelimiter-0.1.1.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6543acd4d41197ad5a82e8cc8c426f398a13a49dd1a9d27496dc1a3ca03de75 |
|
MD5 | 33d2242f46bbda7291d245c8b5840a58 |
|
BLAKE2b-256 | 4759386544c8d1123349e212963946bdc681223b5a2e58547f729cf26faf3daf |
File details
Details for the file timelimiter-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: timelimiter-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c1dc76531687ceeed66c22a0738d50a85b86a5ac15b4b338185d1534370f0d8 |
|
MD5 | d5059cce955ebd412031f652e84834cb |
|
BLAKE2b-256 | 83db2bb849f31da5415664baefbe65ea25d733abfec838a4280d7999cd68a3cf |