FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-151814: Add test for TextIOWrapper.write unbounded memory growth from repeated writes by cmaloney · Pull Request #152244 · python/cpython · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
16 changes: 16 additions & 0 deletions Lib/test/test_io/test_textio.py
This file contains hidden or 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
Expand Up @@ -6,6 +6,7 @@
import sys
import threading
import time
import tracemalloc
import unittest
import warnings
import weakref
Expand Down Expand Up @@ -1522,6 +1523,21 @@ def write(self, data):
t.write("x"*chunk_size)
self.assertEqual([b"abcdef", b"ghi", b"x"*chunk_size], buf._write_stack)

def test_write_empty_no_memory_growth(self):
# gh-151814: Writing empty string should have stable memory usage.
t = self.TextIOWrapper(self.BytesIO())
nwrites = 200_000
tracemalloc.start()
try:
for _ in range(nwrites):
t.write("")
_, peak = tracemalloc.get_traced_memory()
finally:
tracemalloc.stop()

# No longer leaks several bytes per write.
self.assertLess(peak, nwrites)

def test_issue119506(self):
chunk_size = 8192

Expand Down
Loading

Back | FazBrowse Home | New Git URL