gtui
Task scheduler & executor with text-based user interface, able to:
- declare task & dependency as a graph
- execute task graph
- show task status, stdout & log
- provide a nice user interface
To install:
$ pip install gtui
Quickstart
Let's say we have some helloworld tasks & their dependencies like this:
We need to create Task and add them to TaskGraph:
import time
import logging
from gtui import Task, TaskGraph
def foo(n):
logging.info('foo(%s) is called', n)
print('Start to sleep %s seconds.' % n)
time.sleep(n)
print('Hello World!')
t1 = Task('t1', func=foo, args=[0.1])
t2 = Task('t2', func=foo, args=[1])
t3 = Task('t3', func=foo, args=[1])
t4 = Task('t4', func=foo, args=[0.5])
g = TaskGraph()
g.add_task(t1)
g.add_task(t2, waiting_for=t1)
g.add_task(t3, waiting_for=t1)
g.add_task(t4, waiting_for=[t2, t3])
g.run()
TaskGraph.run starts the text user interface, and you can navigate through tasks, see their status, output and logs:
Keybindings:
- t : toggle tail -f mode, will follow text when enabled
- tab : switch between output & log
- j/k : select previous/next task
- h/l : page up/down
- ↑/↓ : scroll up/down one line
- y : copy text
- q : exit
Task & TaskGraph
Task defines what to do and has an unique name:
# foo(*args, **kwargs) will be called
t = Task(name='foo', func=foo, args=[1, 2], kwargs={'foo': 'bar'})
TaskGraph defines execution order of a set of tasks, it provides method to declare task & dependency:
g = TaskGraph()
g.add_task(t1) # added task t1
g.add_task(t2, waiting_for=t1) # added task t2, t2 runs after t1 finishes
g.add_tasks([t3, t4]) # added task t3, t4
g.add_dependency(t3, waiting_for=[t1, t2]) # declare t3 to run after t1 & t2 finish
When TaskGraph contains a cycle denpendency, run method will throw a ValueError. You can also use has_cycle to
check:
> g = TaskGraph()
> g.add_tasks([t1, t2])
> g.add_dependency(t1, waiting_for=t2)
> g.add_dependency(t2, waiting_for=t1)
> g.has_cycle()
[t1, t2, t1]
Run Options
TaskGraph.run provides some options:
g.run(
title='Demo', # Text shown at the left bottom corner
callback=None, # A function called when execution fail or succeed
log_formatter=None, # An instance of logging.Formatter, to specify the log format
exit_on_success=False # whether exit tui when execution succeed
)
callback can be used to notify the execution result, it will be called with an boolean indicating whether execution succeed. gtui.callback has some common callbacks:
# emit a desktop notification, use osascript on mac and notify-send on linux
from gtui import callback
g.run(callback.desktop_nofity(title='Plz See Here!', success_msg='Success', fail_msg='Fail'))
Possible Problem with Stdout
Writing to stdout will break the TUI display. gtui runs each task in a new thread with sys.stdout replaced so functions like print will just work fine. When creating a new thread inside a task, gtui.IORedirectedThread can be used to achieve the same result:
from gtui import IORedirectedThread
t = IORedirectedThread(target=print, args=['hello world'])
t.start()
t.join()
content = t.get_stdout_content()
However, gtui doesn't try to deal with other cases so you should take care of it by yourself.
Metadata
Release files for gtui 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gtui-0.1.1.tar.gz | 17.2 kB | Without provenance | Details for gtui-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gtui-0.1.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for gtui-0.1.1-py2.py3-none-any.whl |
Total release size: 47.1 kB
Release files / gtui-0.1.1.tar.gz
| Download URL | gtui-0.1.1.tar.gz |
|---|---|
| Size | 17.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
63eff172e1c9560576c32b611bc2dd8ef3111b90485b5cd9608a5bf91aa2af70
|
|
BLAKE2b-256 checksum How to use checksums |
48638f087eda220c8289e68937f7284eaf1a2799d1554f27c69a65297599b749
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.20.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.16
|
Release files / gtui-0.1.1-py2.py3-none-any.whl
| Download URL | gtui-0.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 29.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
1a1b0998dd1944dd5a89faee8475a48e80905fe740b7b270f1e66f6804a25c21
|
|
BLAKE2b-256 checksum How to use checksums |
1177a8960565042eac79f5901944682cc104d3776a57e0bd0a5a754367ab5a52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.20.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.16
|
Security for gtui 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.