gets stuck in ansitowin32.py on GitLab CI
See original GitHub issueIssue description
When running pipenv install or pipenv sync on GitLab CI, pipenv gets stuck (at least for 1h, until the job gets killed).
Expected result
It should not get stuck.
Actual result
--verbose does not print any more information. When LANG is set properly, you can’t see any output, otherwise you can read
Warning: the environment variable LANG is not set!
We recommend setting this in ~/.profile (or equivalent) for proper expected behavior.
and after that it hangs.
Steps to replicate
Unfortunately I couldn’t reproduce it on gitlab.com. It happens on our private gitlab in a private repo. Here is a minimal version of a Pipfile:
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
Django = "<2.2.0"
[requires]
# Don't specify the exact python version, because of https://github.com/pypa/pipenv/issues/1050#issuecomment-346203646
python_version = "3"
I only run pipenv install or pipenv sync.
While the job was running / stuck in GitLab CI, I run the exact same command within the docker container, where the CI job was running and it worked. I think, the problem has something to do with how GitLab CI runs the commands. I thought, the problem might be, that stdout is not a tty, but running something like setsid sh -c 'pipenv install' < /dev/null > log 2>&1 did work, too.
I tried running python3 -m trace --trace /usr/bin/pipenv install > trace_log.txt and this is the output
I removed many lines. I think, the last ones are interesting. At the end, it seems, that pipenv is looping forever over:
--- modulename: ansitowin32, funcname: closed
ansitowin32.py(52): stream = self.__wrapped
ansitowin32.py(53): return not hasattr(stream, 'closed') or stream.closed
I already spent hours on debugging, but now, I don’t know what to do…
$ pipenv --support
Pipenv version: '2018.11.26'
Pipenv location: '/usr/lib/python3.7/site-packages/pipenv'
Python location: '/usr/bin/python3'
Python installations found:
3.7.2:/usr/bin/python33.7.2:/usr/bin/python3.7m3.6.8:/usr/bin/python3.6m3.6.8:/usr/bin/python3.63.5.6:/usr/bin/python3.53.5.6:/usr/bin/python3.5m3.5.3:/usr/bin/pypy3.53.4.9:/usr/bin/python3.43.4.9:/usr/bin/python3.4m2.7.15:/usr/bin/python2.7.13:/usr/bin/pypy
PEP 508 Information:
{'implementation_name': 'cpython',
'implementation_version': '3.7.2',
'os_name': 'posix',
'platform_machine': 'x86_64',
'platform_python_implementation': 'CPython',
'platform_release': '4.20.7-200.fc29.x86_64',
'platform_system': 'Linux',
'platform_version': '#1 SMP Wed Feb 6 19:16:42 UTC 2019',
'python_full_version': '3.7.2',
'python_version': '3.7',
'sys_platform': 'linux'}
System environment variables:
CI_COMMIT_SHORT_SHAPIPENV_VENV_IN_PROJECTCI_RUNNER_EXECUTABLE_ARCHCI_COMMIT_TITLECI_JOB_TOKENCI_BUILD_REF_NAMECI_REGISTRY_PASSWORDCI_RUNNER_TAGSCI_PIPELINE_URLGITLAB_CI_PASSWORDCI_JOB_NAMECI_SERVER_VERSIONGITLAB_CICI_SERVER_REVISIONHOSTNAMECI_PROJECT_VISIBILITYCI_DISPOSABLE_ENVIRONMENTCI_COMMIT_SHACI_COMMIT_MESSAGECI_BUILD_STAGECI_PROJECT_URLCI_COMMIT_REF_SLUGCI_SERVER_NAMECI_RUNNER_VERSIONCI_BUILD_NAMECICI_REGISTRY_USERCI_PROJECT_IDCI_PIPELINE_IDCI_JOB_URLCI_COMMIT_DESCRIPTIONPWDGITLAB_FEATURESHOMECI_REGISTRYCI_BUILD_TOKENCI_BUILD_IDGITLAB_USER_NAMECI_COMMIT_BEFORE_SHACI_PROJECT_PATH_SLUGCI_API_V4_URLGITLAB_USER_EMAILCI_COMMIT_REF_NAMECI_SERVER_VERSION_PATCHCI_REGISTRY_IMAGECI_PIPELINE_IIDDISTTAGCI_SERVER_TLS_CA_FILECI_RUNNER_IDFGCCI_SERVERCI_JOB_IDCI_REPOSITORY_URLGITLAB_USER_LOGINCI_RUNNER_REVISIONCI_CONFIG_PATHCI_PROJECT_NAMECI_SERVER_VERSION_MINORCI_SERVER_VERSION_MAJORFF_K8S_USE_ENTRYPOINT_OVER_COMMANDCI_NODE_TOTALSHLVLCI_RUNNER_DESCRIPTIONNPM_TOKENCI_PROJECT_PATHGITLAB_USER_IDCI_BUILD_BEFORE_SHACI_BUILD_REFPATHCI_PIPELINE_SOURCECI_PROJECT_NAMESPACECI_PROJECT_DIRCI_JOB_STAGECI_BUILD_REF_SLUG_OLDPWDPIP_DISABLE_PIP_VERSION_CHECKPYTHONDONTWRITEBYTECODEPIP_SHIMS_BASE_MODULEPIP_PYTHON_PATHPYTHONFINDER_IGNORE_UNSUPPORTED
Pipenv–specific environment variables:
PIPENV_VENV_IN_PROJECT:1
Debug–specific environment variables:
PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binPWD:/
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (3 by maintainers)

Top Related StackOverflow Question
Thanks for that. In fact it works, when you add a shebang to
manage.pyand make it executable. But maybe this is not intended 😄Unfortunately it does not work with any of the variables exported:
ANSI_COLORS_DISABLED=1VISTIR_DISABLE_COLORS=1PIPENV_COLORBLIND=1TERM=dumbPY_COLORS=0The colors are of course disabled, when running pipenv with a TTY. But the bug as described above still exists.
As workaround I’ll add an
unset CIto my scripts:Hrm, that’s actually helpful though. Up and down the stack
pipenvand https://github.com/sarugaku/vistir (which is what we use for the spinner library) are sensitive to theCIvariable which toggles colors on and offThe error logs were even more helpful, I think this was a bug with the old stream wrapper we used to wrap the
stderrandstdoutstreams both inpipenvand in the resolver subprocesses. On the master branch (also invistirnow), we have switched over to a different implementation which provides an uncloseable stream wrapper which I believe was the source of the problem. Interestingly I was not able to reproduce this using Ubuntu-based images but I was successful using fedora based images.Using the following dockerfile I managed to reproduce the problem, which I then resolved simply by installing a wheel built from the master branch of pipenv – I simply uncommented the specified line:
My pipfile for this build contains:
With the
.devwheel commented out, the docker container builds forever. If I uncomment that line, the container builds in 32 seconds. I am going to close this out as resolved on master, once we cut the next release you will be able to unset yourCI: ""workarounds. Thanks a ton for the debugging help, I don’t think we would have tracked this down without it