Skip to content

gh-136421: Load _datetime static types during interpreter initialization #136583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 21, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a test case.
  • Loading branch information
ZeroIntensity committed Jul 12, 2025
commit 963a9ee58be7635b42c2dcc11c1fbef6500c09c5
29 changes: 29 additions & 0 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -3651,6 +3651,35 @@ def test_repr_subclass(self):
td = SubclassDatetime(2010, 10, 2, second=3)
self.assertEqual(repr(td), "SubclassDatetime(2010, 10, 2, 0, 0, 3)")

@support.cpython_only
def test_concurrent_initialization(self):
try:
from concurrent.futures import InterpreterPoolExecutor as _
except ImportError:
self.skipTest("requires subinterpreters")

try:
import _datetime as _
except ImportError:
self.skipTest("requires C implementation of datetime")

# Run in a subprocess to ensure we get a clean version of _datetime
script = """if True:
from concurrent.futures import InterpreterPoolExecutor

def func():
import _datetime
print('a', end='')

with InterpreterPoolExecutor() as executor:
for _ in range(8):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's up to you, but range(10) is probably better than range(8) for the Windows x64 CI to reproduce the issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, I think this is fine. Many other systems have 8 cores, not 10.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but it sounds like you are talking about the max_workers argument rather than the submit count here.

Copy link
Member Author

@ZeroIntensity ZeroIntensity Jul 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_workers just chooses the number of threads on the system when not set. We could try to submit os.cpu_count() number of futures, but we don't need to overcomplicate this; we just need something that stresses several subinterpreters trying to import _datetime concurrently.

executor.submit(func)
"""
rc, out, err = script_helper.assert_python_ok("-c", script)
self.assertEqual(rc, 0)
self.assertEqual(out, b"a" * 8)
self.assertEqual(err, b"")


class TestSubclassDateTime(TestDateTime):
theclass = SubclassDatetime
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy