uvloop icon indicating copy to clipboard operation
uvloop copied to clipboard

create_subprocess_exec treats env={} differently than vanilla asyncio

Open byllyfish opened this issue 4 years ago • 0 comments

  • 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)

byllyfish avatar Aug 21 '21 05:08 byllyfish