Open red8888 opened 1 year ago
Based on this github issue I think I found a solution: https://github.com/pyinvoke/invoke/issues/689
@task
def my_cmd(ctx: Context):
invoke_promise = ctx.run(
"while true; do echo running forevah; sleep 2; done", warn=True, hide=False, echo=True, asynchronous=True
)
import time
time.sleep(10) # ie do a bunch of work in the foreground
# Check the current output of backgroud process
current_output = invoke_promise.runner.stdout
# ... parse current output and do stuff
# Based on current output decide if and when to kill it
invoke_promise.runner.kill()
Is this how I should be doing this?
FYI created an SO post too: https://stackoverflow.com/questions/76491927/how-do-i-read-the-current-output-with-asynchronous-without-waiting-for-the-proce/76492139#76492139
Its documented, but are there any complete examples and snippets for how to use
asynchronous=True
?I usually have to look through github issues when trying to find full example snippets to stuff, but maybe I'm just missing this in the docs.
Im doing this
This throws an error
This hangs forever until the process exits
print(invoke_promise.join())
What method is there on the returned promise object to just get the current output of the running background process that was started?
I want to be able to: