Async command-line runner
Project description
ACONS
An asynchronous command-line runner for use in async web-servers like fastapi.
Sometimes, you want to run command-line utilities and expose the output to a web-server. However, it's a bit tricky to capture the console output while it's running, and also allow the web-client to kill the job mid-process.
acons
can execute command-line processes as an async function, where output can be retrieved via another async function, and a kill signal can be sent at any time.
Install
pip install acons
run
Function interface:
run(command, run_dir=None, is_parse=False, job_id=None)
command
: str of command-line commandrun_dir
: optional starting directory of the commandis_parse
: optional flag to parse the output as tsv file into a list of dictionariesjob_id
: optional id that will be used toflush_lines
andkill_job
To use in an async function:
await acons.run('ls', job_id='my-special-id-123')
To test the output in a sync version:
import acons
output = acons.sync_run('ls')
flush_lines
In an async function:
lines = await acons.flush_lines('my-special-id-123')
This will return the console lines produced by the job since the last call to acons.flush_lines
kill_job
In an async function:
`await kill_job('my-special-id-123')
Sends the kill signal for the job.
Parameters d
acons.RUN_INTERVAL_IN_S = 0.2
- determines how long the function polls for each interval
acons.SLEEP_INTERVAL_IN_S = 0.5
- determines how long the function sleeps between intervals
acons.N_MAX_JOB = 100
- maximum number of jobs that stores output using an LRU cache
Example server
A simple fastapi-server/vue-client is included that demonstrates acons
in action.
Concurrent command-line commands can be typed in and executed. The console output will be piped back into the web-client, and the job can be cancelled at any time.
When the job is completed, the entire console output is made available through the Monaco web-editor .
Download the .zip version of this package, then run the server:
./test-server.sh
which is essentially:
uvicorn server:app --reload --port=5200
Communication between client/server is via an rpc-json interface as described in rpcseed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file acons-0.1.1.tar.gz
.
File metadata
- Download URL: acons-0.1.1.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44edce3d61ec917437ac42209bef703feebc20b2d1eafcfad89a1da8873f9b28 |
|
MD5 | d8d981efc8c5e5bda0db76879899e4e8 |
|
BLAKE2b-256 | 510b5de7a8ad50c4e74efcf22eb444dea59c45797ca8f882164b4d16b7f1b680 |