forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythongh-125286: Add test for single-phase init and shared objects.
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Helper module for _testembed.c test_subinterpreter_finalize test. | ||
""" | ||
|
||
import sys | ||
|
||
PREFIX = "shared_string_" | ||
SUFFIX = "DByGMRJRSEDp29PkiZQNHA" | ||
|
||
def init_sub1(): | ||
import _testsinglephase | ||
# Create global object to be shared when imported a second time. | ||
_testsinglephase._shared_list = [] | ||
# Create a new interned string, to be shared with the main interpreter. | ||
_testsinglephase._shared_string = sys.intern(PREFIX + SUFFIX) | ||
|
||
|
||
def init_sub2(): | ||
# This sub-interpreter will share a reference to _shared_list with the | ||
# first interpreter, since importing _testsinglephase will not initialize | ||
# the module a second time but will just copy the global dict. This | ||
# situtation used to trigger a bug like gh-125286 if TraceRefs was enabled | ||
# for the build. | ||
import _testsinglephase | ||
|
||
|
||
def init_main(): | ||
global shared_str | ||
# The first sub-interpreter has already interned this string value. The | ||
# return value from intern() will be the same string object created in | ||
# sub-interpreter 1. Assign it to a global so it lives until the main | ||
# interpreter is shutdown. | ||
shared_string = sys.intern(PREFIX + SUFFIX) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters