mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-98896: resource_tracker: use json&base64 to allow arbitrary shared memory names (GH-138473)
This commit is contained in:
parent
70748bdbea
commit
c6f3dd6a50
3 changed files with 97 additions and 8 deletions
|
|
@ -7364,3 +7364,46 @@ def test_forkpty(self):
|
|||
res = assert_python_failure("-c", code, PYTHONWARNINGS='error')
|
||||
self.assertIn(b'DeprecationWarning', res.err)
|
||||
self.assertIn(b'is multi-threaded, use of forkpty() may lead to deadlocks in the child', res.err)
|
||||
|
||||
@unittest.skipUnless(HAS_SHMEM, "requires multiprocessing.shared_memory")
|
||||
class TestSharedMemoryNames(unittest.TestCase):
|
||||
def test_that_shared_memory_name_with_colons_has_no_resource_tracker_errors(self):
|
||||
# Test script that creates and cleans up shared memory with colon in name
|
||||
test_script = textwrap.dedent("""
|
||||
import sys
|
||||
from multiprocessing import shared_memory
|
||||
import time
|
||||
|
||||
# Test various patterns of colons in names
|
||||
test_names = [
|
||||
"a:b",
|
||||
"a:b:c",
|
||||
"test:name:with:many:colons",
|
||||
":starts:with:colon",
|
||||
"ends:with:colon:",
|
||||
"::double::colons::",
|
||||
"name\\nwithnewline",
|
||||
"name-with-trailing-newline\\n",
|
||||
"\\nname-starts-with-newline",
|
||||
"colons:and\\nnewlines:mix",
|
||||
"multi\\nline\\nname",
|
||||
]
|
||||
|
||||
for name in test_names:
|
||||
try:
|
||||
shm = shared_memory.SharedMemory(create=True, size=100, name=name)
|
||||
shm.buf[:5] = b'hello' # Write something to the shared memory
|
||||
shm.close()
|
||||
shm.unlink()
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error with name '{name}': {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
print("SUCCESS")
|
||||
""")
|
||||
|
||||
rc, out, err = assert_python_ok("-c", test_script)
|
||||
self.assertIn(b"SUCCESS", out)
|
||||
self.assertNotIn(b"traceback", err.lower(), err)
|
||||
self.assertNotIn(b"resource_tracker.py", err, err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue