python / python/cpython

sockets and asyncio on Windows depend on SYSTEMROOT env var

Open
#118,234 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs easy topic-socket
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:
os.environ.clear() # THIS WAS THE CAUSE!!!
import asyncio

This causes the following:

Traceback (most recent call last):
  File "c:\Users\user\Documents\Development\main\main.py", line 3, in <module>
    import asyncio
  File "C:\Program Files\Python311\Lib\asyncio\__init__.py", line 42, in <module>
    from .windows_events import *
  File "C:\Program Files\Python311\Lib\asyncio\windows_events.py", line 8, in <module>
    import _overlapped
OSError: [WinError 10106] The requested service provider could not be loaded or initialized

It took me a whole day to figure out that os.environ.clear() causes this bug to occur. I'm not sure if this is supposed to occur, I just thought I would post this in case other people are struggling with this.

CPython versions tested on:

3.8, 3.9, 3.10, 3.11

Operating systems tested on:

Windows

Linked PRs
  • gh-134363
  • gh-134435

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the reported import path through asyncio/init.py and asyncio/windows_events.py, then inspect linked PRs gh-134363 and gh-134435. Reproduce the failure on Windows with os.environ.clear() before importing asyncio and use the existing discussion to determine the expected behavior and completion criteria.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.