diff --git a/sdks/python/apache_beam/yaml/yaml_provider.py b/sdks/python/apache_beam/yaml/yaml_provider.py index 5a3ccf6b0c2e..f1408b5b0d1c 100755 --- a/sdks/python/apache_beam/yaml/yaml_provider.py +++ b/sdks/python/apache_beam/yaml/yaml_provider.py @@ -1412,7 +1412,13 @@ def _create_venv_from_clone( @classmethod def _create_venv_to_clone(cls, base_python: str) -> str: - if '.dev' in beam_version: + # For '.dev', the default clone source is the venv that owns base_python. + # In CI that is often the active tox/sandbox tree; clonevirtualenv can + # race with ephemeral paths (tmp/, caches) under that tree. Use the + # scratch clonable venv in CI instead. Locally, keep cloning the dev venv + # for speed. + _ci = os.environ.get('CI', '').lower() in ('true', '1', 'yes') + if '.dev' in beam_version and not _ci: base_venv = os.path.dirname(os.path.dirname(base_python)) print('Cloning dev environment from', base_venv) return base_venv