How do I read the current output with asynchronous without waiting for the process to finish?
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start with Invoke's documentation for asynchronous=True and the returned Promise, then compare the shown print(invoke_promise) and invoke_promise.join() behavior. Provide complete examples for observing output without waiting and manually stopping the process, or document the limitation if that is not supported.
Written by the indexing model from the issue text.
Description
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
@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
)
This throws an error
print(invoke_promise)
Traceback (most recent call last):
File "/usr/local/bin/myproject", line 8, in <module>
sys.exit(program.run())
File "/usr/local/lib/python3.10/site-packages/invoke/program.py", line 384, in run
self.execute()
File "/usr/local/lib/python3.10/site-packages/invoke/program.py", line 569, in execute
executor.execute(*self.tasks)
File "/usr/local/lib/python3.10/site-packages/invoke/executor.py", line 129, in execute
result = call.task(*args, **call.kwargs)
File "/usr/local/lib/python3.10/site-packages/invoke/tasks.py", line 127, in __call__
result = self.body(*args, **kwargs)
File "/workspaces/myproject/myproject/tasks/mytask.py", line 479, in my_cmd
print(invoke_promise)
File "/usr/local/lib/python3.10/site-packages/invoke/runners.py", line 1475, in __str__
if self.exited is not None:
AttributeError: 'Promise' object has no attribute 'exited'
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:
- Just see the current output so far without waiting for it to finish
- Be able to read the output of the currently running process and choose to manually kill it if I want
- Dominant language
- Python
- Stars
- 4.8k
- Forks
- 412
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pyinvoke/invoke
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100