Skip to content

Commit

Permalink
Merge branch 'main' into parallel-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Mar 12, 2024
2 parents fcf17fc + 388d4be commit 88afd39
Show file tree
Hide file tree
Showing 14 changed files with 475 additions and 481 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/assess-file-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v29.0.4
uses: tj-actions/changed-files@v41.0.0

- name: Assess Source Code Changes
id: assess-changes
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ jobs:

- name: Run full pytest with coverage
run: |
pytest -vv -rsx --cov=tqdm_publisher --cov-report xml:./codecov.xml
cat ./codecov.xml
pytest -vv -rsx --cov=tqdm_publisher --cov-report xml:./coverage.xml
cat ./coverage.xml
- name: Upload full coverage to Codecov
if: ${{ matrix.python-version == '3.11' && matrix.os == 'ubuntu-latest' }}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./codecov.xml
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
Expand Down
161 changes: 157 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,160 @@
__pycache__/
*.egg-info
dist
# Dataset file / log file types:
/**/*.log

# Byte-compiled / optimized / DLL files
/**/__pycache__/
*.py[cod]

# Datasets:
/tests/testdatasets/

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
codecov.xml
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Sphinx documentation
docs/build
docs/make.bat
docs/Makefile

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

#Mac
.DS_Store

# Vscode
.vscode/
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

# Spyder
.spyproject/
50 changes: 32 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,50 @@ This is useful if you want to use `tqdm` to track the progress of a long-running
```bash
pip install tqdm_publisher
```
## Getting Started
### Basic Usage
To monitor the progress of an existing `tqdm` progress bar, simply swap the `tqdm`and `TQDMPublisher` constructors. Then, declare a callback function to handle progress updates, and subscribe it to the `TQDMPublisher` updates using the `subscribe` method _before iteration begins_.

## Usage
#### Original Code
```python
import random
import asyncio
import time

from tqdm_publisher import TQDMPublisher
from tqdm import tqdm

N_TASKS = 100

# Create a list of tasks
durations = [ random.uniform(0, 1.0) for _ in range(N_TASKS) ]

# Create a progress bar
progress_bar = tqdm(durations)

async def sleep_func(sleep_duration = 1):
await asyncio.sleep(delay=sleep_duration)
# Iterate over the progress bar
for duration in progress_bar:
time.sleep(duration) # Execute the task
```

async def run_multiple_sleeps(sleep_durations):
#### Modified Code

tasks = []
```python
import random
import time

for sleep_duration in sleep_durations:
task = asyncio.create_task(sleep_func(sleep_duration=sleep_duration))
tasks.append(task)
from tqdm_publisher import TQDMPublisher

progress_bar = TQDMPublisher(asyncio.as_completed(tasks), total=len(tasks))
callback_id = progress_bar.subscribe(lambda info: print('Progress Update', info))
N_TASKS = 100
durations = [ random.uniform(0, 1.0) for _ in range(N_TASKS) ]
progress_bar = TQDMPublisher(durations)

for f in progress_bar:
await f
# Declare a callback function to handle progress updates
on_update = lambda info: print('Progress Update', info)

progress_bar.unsubscribe(callback_id)
# Subscribe the callback to the TQDMPublisher
progress_bar.subscribe(on_update)

number_of_tasks = 10**5
sleep_durations = [random.uniform(0, 5.0) for _ in range(number_of_tasks)]
asyncio.run(run_multiple_sleeps(sleep_durations=sleep_durations))
for duration in progress_bar:
time.sleep(duration)
```

## Demo
Expand Down
Loading

0 comments on commit 88afd39

Please sign in to comment.