Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amcat/progressmonitor
Python classes for tracking (sub)task progress (inspired by Eclipse ProgressMonitor, but more pythonic)
https://github.com/amcat/progressmonitor
Last synced: 4 days ago
JSON representation
Python classes for tracking (sub)task progress (inspired by Eclipse ProgressMonitor, but more pythonic)
- Host: GitHub
- URL: https://github.com/amcat/progressmonitor
- Owner: amcat
- License: mit
- Created: 2016-12-11T10:30:05.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-11T21:59:39.000Z (almost 8 years ago)
- Last Synced: 2024-09-22T09:16:07.680Z (about 2 months ago)
- Language: Python
- Size: 11.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ccamel - amcat/progressmonitor - Python classes for tracking (sub)task progress (inspired by Eclipse ProgressMonitor, but more pythonic) (Python)
README
# Progress Monitor
Python classes for tracking (sub)task progress (inspired by Eclipse ProgressMonitor, but more pythonic)
## Installation
Install directly from pypi:
```{sh}
pip install progressmonitor
```## Usage
(See also [example.py](example.py))
### Initialization and task updates
A monitor keeps track of progress in units specified by the task.
A progress monitor is initialized with .begin(), which sets the total amount of work to be done.
Calls to update() (and optionally, done()) increment the amount of work doneNote that task name and total work is set on .begin(), not on construction, because normally
the task will receive a monitor from the code calling it.```{py}
m = ProgressMonitor()
m.begin("task name", total_units[, message])
m.update(units[, message])
[m.done()]
```### Adding listeners
You can query progress and message directly with m.progress and m.message,
but in many cases you want to add a listener, which is called with the monitor as argument for every update.
A listener that outputs to the python logging facility is included:```{py}
from progressmonitor import log_listener
m.add_listener(log_listener(mylog, logging.DEBUG))
```### Submonitors
In most cases, a task will call various other tasks as part of its work.
These subtasks can report progress to the monitor.
Since the task and subtasks don't know how much total work the other has, two pieces of information are given:
The weight (amount of units) of the subtask for the main task and the total amount of units in the subtask.
The first is given on creating the sub monitor (in the main task), the second on calling .begin (in the subtask):```{py}
# in the main task:
m = ProgressMonitor()
m.begin(100)
sm = m.submonitor(50) # this submonitor will count for 50 out of the main monitor's 100 units# in the subtask:
sm.begin(10, "subtask name") # this submonitor has 10 units of work in total
sm.update(1) # this will count as 1/10 * 50 = 5 out of 100 units of the main task monitor
sm.done() # this will 'update' the remainig units of m's work, i.e. main progress will now be 50%
```
### Context Managers and DecoratorsTo reduce the boilerplate in working with progress monitors, two context managers and a decorator are provided:
```{py}
@monitored(100)
def supertask(monitor):
...
with monitor.submonitor(50) as sm:
subtask(sm)@monitored(10, name="My first subtask")
def subtask(monitor):
monitor.update(5) # this will update 5/10 * 50/100 = 25% of supertask's work
```