-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-140025: fix queue.SimpleQueue.__sizeof__() computation #140086
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
base: main
Are you sure you want to change the base?
Changes from 15 commits
08e4869
62cd141
a0a23b1
be61a22
dc4b475
d3e633e
192bb61
97ee255
7db6821
18869eb
f3e6e18
b2207aa
5547af4
faf79d4
9339f37
b05e138
a735367
3b228f8
121d680
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1010,13 +1010,38 @@ class C: | |
self.assertIsNone(wr()) | ||
|
||
|
||
|
||
|
||
class PySimpleQueueTest(BaseSimpleQueueTest, unittest.TestCase): | ||
|
||
queue = py_queue | ||
def setUp(self): | ||
self.type2test = self.queue._PySimpleQueue | ||
super().setUp() | ||
|
||
def test_sizeof(self): | ||
q = self.type2test() | ||
|
||
empty_size = q.__sizeof__() | ||
self.assertGreater(empty_size, 0) | ||
|
||
for i in range(8): | ||
q.put(object()) | ||
|
||
size_after_8 = q.__sizeof__() | ||
|
||
q.put(object()) | ||
size_after_9 = q.__sizeof__() | ||
self.assertGreaterEqual(size_after_9, size_after_8) | ||
fatelei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
large_q = self.type2test() | ||
for i in range(1000): | ||
large_q.put(object()) | ||
|
||
large_size = large_q.__sizeof__() | ||
self.assertGreater(large_size, 0) | ||
|
||
|
||
|
||
@need_c_queue | ||
class CSimpleQueueTest(BaseSimpleQueueTest, unittest.TestCase): | ||
|
@@ -1027,37 +1052,30 @@ def setUp(self): | |
self.type2test = self.queue.SimpleQueue | ||
super().setUp() | ||
|
||
def test_is_default(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why were those tests removed???? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean, no need? why touch other tests that are not part of what the PR should address? please only make relevant changes and do not touch unrelated code in the same PR. |
||
self.assertIs(self.type2test, self.queue.SimpleQueue) | ||
self.assertIs(self.type2test, self.queue.SimpleQueue) | ||
|
||
def test_reentrancy(self): | ||
# bpo-14976: put() may be called reentrantly in an asynchronous | ||
# callback. | ||
q = self.q | ||
gen = itertools.count() | ||
N = 10000 | ||
results = [] | ||
|
||
# This test exploits the fact that __del__ in a reference cycle | ||
# can be called any time the GC may run. | ||
|
||
class Circular(object): | ||
def __init__(self): | ||
self.circular = self | ||
|
||
def __del__(self): | ||
q.put(next(gen)) | ||
|
||
while True: | ||
o = Circular() | ||
q.put(next(gen)) | ||
del o | ||
results.append(q.get()) | ||
if results[-1] >= N: | ||
break | ||
|
||
self.assertEqual(results, list(range(N + 1))) | ||
def test_sizeof(self): | ||
q = self.type2test() | ||
|
||
empty_size = q.__sizeof__() | ||
self.assertGreater(empty_size, 0, "Empty C SimpleQueue should have non-zero size") | ||
fatelei marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
for i in range(8): | ||
q.put(object()) | ||
|
||
size_after_8 = q.__sizeof__() | ||
|
||
q.put(object()) | ||
size_after_9 = q.__sizeof__() | ||
self.assertGreaterEqual(size_after_9, size_after_8) | ||
|
||
large_q = self.type2test() | ||
for i in range(1000): | ||
large_q.put(object()) | ||
|
||
large_size = large_q.__sizeof__() | ||
|
||
self.assertGreater(large_size, empty_size) | ||
|
||
self.assertGreater(large_size, empty_size * 2) | ||
|
||
|
||
if __name__ == "__main__": | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix ``queue.SimpleQueue.__sizeof__()`` computation. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.