Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
12 changes: 12 additions & 0 deletions Lib/test/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from test.support import gc_collect, bigmemtest
from test.support import import_helper
from test.support import threading_helper
import sys
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Move import sys up between import random and import threading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, I missed that. I thought running pre-commit run would take care of it.

from test import support

# queue module depends on threading primitives
threading_helper.requires_working_threading(module=True)
Expand Down Expand Up @@ -1031,6 +1033,16 @@ def test_is_default(self):
self.assertIs(self.type2test, self.queue.SimpleQueue)
self.assertIs(self.type2test, self.queue.SimpleQueue)

def test_simplequeue_sizeof_reflects_buffer_growth(self):
q = self.type2test()
before = sys.getsizeof(q)
for _ in range(1000):
q.put(object())
after = sys.getsizeof(q)
self.assertGreater(after, before)
ptr = support.calcobjsize("P") - support.calcobjsize("")
self.assertEqual((after - before) % ptr, 0)
Comment thread
Aniketsy marked this conversation as resolved.
Outdated

def test_reentrancy(self):
# bpo-14976: put() may be called reentrantly in an asynchronous
# callback.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``queue.SimpleQueue.__sizeof__()`` computation.
Comment thread
Aniketsy marked this conversation as resolved.
Outdated
16 changes: 16 additions & 0 deletions Modules/_queuemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@ simplequeue_traverse(PyObject *op, visitproc visit, void *arg)
return 0;
}

/*[clinic input]
@critical_section
_queue.SimpleQueue.__sizeof__ -> Py_ssize_t

Returns size in memory, in bytes.
[clinic start generated code]*/

static Py_ssize_t
_queue_SimpleQueue___sizeof___impl(simplequeueobject *self)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you put the definition of this method after the definition of qsize please?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, I’ll update this.

/*[clinic end generated code: output=58ce4e3bbc078fd4 input=a3a7f05c9616598f]*/
{
Py_ssize_t res = sizeof(simplequeueobject);
res += self->buf.items_cap * sizeof(PyObject *);
return res;
}
Comment thread
Aniketsy marked this conversation as resolved.
Outdated
/*[clinic input]
@classmethod
_queue.SimpleQueue.__new__ as simplequeue_new
Expand Down Expand Up @@ -534,6 +549,7 @@ static PyMethodDef simplequeue_methods[] = {
_QUEUE_SIMPLEQUEUE_PUT_METHODDEF
_QUEUE_SIMPLEQUEUE_PUT_NOWAIT_METHODDEF
_QUEUE_SIMPLEQUEUE_QSIZE_METHODDEF
_QUEUE_SIMPLEQUEUE___SIZEOF___METHODDEF
{"__class_getitem__", Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{NULL, NULL} /* sentinel */
Expand Down
32 changes: 31 additions & 1 deletion Modules/clinic/_queuemodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading