https://github.com/jannchie/inch
https://github.com/jannchie/inch
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jannchie/inch
- Owner: Jannchie
- Created: 2024-10-22T15:50:51.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-05T18:33:43.000Z (over 1 year ago)
- Last Synced: 2025-03-01T15:58:56.501Z (over 1 year ago)
- Language: Python
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# inch
Inch is a Python library specifically designed to manage and execute long-running tasks in batches using multithreading. It enhances the user experience by providing a visual progress display through the rich library. The name "Inch" reflects its core functionality, enabling tasks to "move along slowly and carefully," thus ensuring a systematic and controlled execution process.
## DEMO
[Online Demo](https://asciinema.org/a/687421)
## Features
- Define concurrent tasks using an abstract base class.
- Execute multiple tasks concurrently with adjustable worker threads.
- Track and display task progress using the rich library.
## Installation
Inch can be installed using pip:
```bash
pip install inch
```
Show demo:
```bash
python -m inch
```
## Usage
Here's an example of how to use Inch to execute a simple task:
```python
from inch import Inch, InchPoolExecutor
import random
from time import sleep
class TestTask(Inch):
def __call__(self):
while self.completed < self.total:
self.completed += random.randint(1, 200)
sleep(0.1)
class TestTaskNoProgress(Inch):
def __call__(self):
completed = 0
while completed < 1200:
completed += random.randint(1, 200)
sleep(0.1)
with InchPoolExecutor() as executor:
for i in range(20):
if i % 5 == 0:
executor.start_inch(TestTaskNoProgress(name=f"Task {i+1}"))
else:
executor.start_inch(TestTask(name=f"Task {i+1}", total=1000))
```