Skip to content

Project virtual environment creation is not concurrency-safe #11219

@charliermarsh

Description

@charliermarsh

E.g., this script fails if you run it repeatedly:

#!/bin/bash

rm -rf uvtest
mkdir -p uvtest
cd uvtest
uv init
rm -rf uvtest/.venv

run_python() {
  uv run python -c "print('Hello from process $1')"
}

for i in {1..5}; do
  run_python $i &
done

wait
# Return to original directory
cd - > /dev/null

With some combination of:

❯ ./sync.sh
Initialized project `uvtest`
Using CPython 3.13.0
Creating virtual environment at: .venv
error: Project virtual environment directory `/Users/crmarsh/workspace/puffin/uvtest/.venv` cannot be used because it is not a valid Python environment (no Python executable was found)
error: Project virtual environment directory `/Users/crmarsh/workspace/puffin/uvtest/.venv` cannot be used because it is not a valid Python environment (no Python executable was found)
Using CPython Using CPython 3.13.03.13.0

error: Project virtual environment directory `/Users/crmarsh/workspace/puffin/uvtest/.venv` cannot be used because it is not a compatible environment but cannot be recreated because it is not a virtual environment
error: Project virtual environment directory `/Users/crmarsh/workspace/puffin/uvtest/.venv` cannot be used because it is not a compatible environment but cannot be recreated because it is not a virtual environment
Hello from process 4

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions