I'm trying to read the output of the "pipenv install" (pipenv==2018.11.26, Python 3.6.0) command run via subprocess.Popen as the output is produced, i.e. not when the whole process has ended, because depending on the amount of data it has to download, on the connection speed, etc it might take a long time.
I'm printing all stdout and stderr messages and adding a prefix to them, but I still can't understand where this sort of "spinner" message: "[== ] Creating virtual environment..." is coming from.
Here's the complete code I'm running
import subprocess
import threading
cmd = ['pipenv', 'install','--ignore-pipfile']
cwd = 'test'
def run_cmd(cmd,cwd):
popen = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,bufsize=1)
a = threading.Thread(target=printTh,args=("stdout",iter(popen.stdout.readline, b"")))
a.start()
b = threading.Thread(target=printTh,args=("stderr",iter(popen.stderr.readline, b"")))
b.start()
while popen.poll() is not None:
a.join()
b.join()
def printTh(pipe_name,iter):
for line in iter:
print(pipe_name+"->"+line.rstrip().decode("utf-8"), end = "\r\n",flush =True)
run_cmd(cmd,cwd)
On my gui console I can see that everything has a prefix except the spinner "[ ===] Creating virtual environment.." message that doesn't belong to neither stderr not stdout:
Console print:
stderr->Creating a virtualenv for this project…
stderr->Pipfile: C:\Users\ahadu\test\Pipfile
stderr->Using C:/Program Files (x86)/Anaconda3/python.exe (3.6.0) to create virtualenv…
[ ===] Creating virtual environment...Running virtualenv with interpreter C:/Program Files (x86)/Anaconda3/python.exe
stderr->Already using interpreter C:\Program Files (x86)\Anaconda3\python.exe
stderr->Using base prefix 'C:\\Program Files (x86)\\Anaconda3'
stderr-> No LICENSE.txt / LICENSE found in source
stderr->New python executable in C:\Users\ahadu\test\.venv\Scripts\python.exe
stderr->Installing setuptools, pip, wheel...
stderr->done.
stderr->
stderr-Successfully created virtual environment!
stderr->Virtualenv location: C:\Users\ahadu\test\.venv
stdout->Installing dependencies from Pipfile.lock (d34422)…
stdout->To activate this project's virtualenv, run pipenv shell.
stdout->Alternatively, run a command inside the virtualenv with pipenv run.
Process finished with exit code 0
Where does this message come from? This is also where it might take some time, so not being able to read this message as it gets produced, undermines the whole work.
In other words, what I expect is to see the following print on the console:
some-source->[= ] Creating virtual environment...
some-source->[ =] Creating virtual environment...
some-source->[= ] Creating virtual environment...
some-source->[ =] Creating virtual environment...
until it has finished.
Does anyone know the reason for this issue and how to address it?