There's this external python script that I would like to call. It provides an async mode so that it returns the task id before it completes the whole process.
The mechanism works well when I execute in the command line. The task id returns on stdout immediately. But the main process actually forks a subprocess to do the backend job. So when I want to use bash script to get the task id, it hangs until the subprocess finishes. It's not async at all.
So my question is, how can I get the main process output immediately instead of waiting for the subprocess complete?
e.g.
$ ./cmd args
{"task": 1}
$ x=`./cmd args`
<< it hungs until entire process completed and returns all result at once.
{"task": 1} {"task": 1} {"actual_result": "xxx"}
// It's the same using python
import subprocess
p = subprocess.Popen(["cmd", "args"], stdout= subprocess.PIPE, stderr = subprocess.PIPE)
out, err = p.communicate()
<< stuck here as well