Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature proposal: JSON output to arbitrary FD to allow programmatic consumers #1539

Open
3 of 6 tasks
charles-dyfis-net opened this issue Dec 22, 2023 · 0 comments
Open
3 of 6 tasks

Comments

@charles-dyfis-net
Copy link

This ticket is spawned by a recent Stack Overflow question, grep a live progress bar from a running program. The party asking this question was looking for a way to run a piece of software -- which, as it turns out, uses tqdm for its progress bar -- and monitor its progress programmatically, triggering an event when that progress exceeded a given threshold.

This is not an unreasonable request, and I've occasionally had the need for similar things in my career. Generally, solving such problems ends up going one of a few routes:

  • Patching the software being run to add hooks that trigger when progress meets desired milestones (unfortunate because invasive).
  • Parsing the output stream being generated (unfortunate because fragile -- prone to break when the progress bar format is updated, the curses or similar library being used to generate events changes, the terminal type or character set in use differs from that which the folks building the parser anticipated, etc).
  • Leveraging support for writing progress information in a well-defined format to a well-defined destination.

This is a feature request to make the 3rd of those available by default across all applications using TQDM.

One reasonable interface accessible to non-Python consumers would be environment variables, such as:

TQDM_FD=3 TQDM_FORMAT=json appname...

...to instruct progress data to be written to file descriptor 3 (aka the file-like object returned by os.fdopen(3, 'a')) in JSONL form, such that whatever software is spawning appname can feed contents through a JSON parser. Some examples from the README might in this form look like:

{"units": "bytes", "total_units": 369098752, "curr_units": 160432128, "pct": 44, "units_per_second": 11534336, "state": "Processing", "time_spent": "00:14", "time_remaining": "00:18"}
{"units": "bytes", "total_units": 369098752, "curr_units": 155189248, "pct": 42, "units_per_second": 11429478, "state": "Compressed", "time_spent": "00:14", "time_remaining": "00:19"}

...allowing out-of-process tools written in non-Python languages to perform arbitrary operations based on that status.


  • I have marked all applicable categories:
    • documentation request (i.e. "X is missing from the documentation." If instead I want to ask "how to use X?" I understand StackOverflow#tqdm is more appropriate)
    • new feature request
  • I have visited the source website, and in particular
    read the known issues
  • I have searched through the issue tracker for duplicates
  • I have mentioned version numbers, operating system and
    environment, where applicable:
    import tqdm, sys
    print(tqdm.__version__, sys.version, sys.platform)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant