Skip to content

create_subprocess_exec treats env={} differently than vanilla asyncio #439

Closed
@byllyfish

Description

@byllyfish
Contributor
  • uvloop version: 0.16.0
  • Python version: 3.9.6
  • Platform: macOS 11.5.2
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: yes
  • Does uvloop behave differently from vanilla asyncio? How?: create_subprocess_exec treats env differently.

When I set env={}, uvloop treats this as None and inherits all environment variables, while vanilla asyncio treats {} as an empty environment.

import asyncio
import os

import pytest

if os.environ.get("UVLOOP"):
    # Install uvloop event loop.
    import uvloop

    @pytest.fixture
    def event_loop():
        loop = uvloop.new_event_loop()
        yield loop
        loop.close()


@pytest.mark.asyncio
async def test_env():
    "This test passes under vanilla asyncio but fails under uvloop."
    proc = await asyncio.create_subprocess_exec(
        "/usr/bin/env",
        stdout=asyncio.subprocess.PIPE,
        env={},
    )
    result = await proc.communicate()

    # Under uvloop, stdout contains the full, inherited environment.
    assert result == (b"", None)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @byllyfish

      Issue actions

        create_subprocess_exec treats env={} differently than vanilla asyncio · Issue #439 · MagicStack/uvloop