Skip to content

gh-76785: Minor Improvements to "interpreters" Module #116328

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

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add low-level tests.
  • Loading branch information
ericsnowcurrently committed Mar 4, 2024
commit b15e706773d00ecb90533c2023ed3ac89242f4c1
65 changes: 63 additions & 2 deletions Lib/test/test_interpreters/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
_queues = import_helper.import_module('_xxinterpqueues')
from test.support import interpreters
from test.support.interpreters import queues
from .utils import _run_output, TestBase
from .utils import _run_output, TestBase as _TestBase


class TestBase(TestBase):
def get_num_queues():
return len(_queues.list_all())


class TestBase(_TestBase):
def tearDown(self):
for qid in _queues.list_all():
try:
Expand All @@ -35,6 +39,63 @@ def test_highlevel_reloaded(self):
# See gh-115490 (https://github.com/python/cpython/issues/115490).
importlib.reload(queues)

def test_create_destroy(self):
qid = _queues.create(2, 0)
_queues.destroy(qid)
self.assertEqual(get_num_queues(), 0)
with self.assertRaises(queues.QueueNotFoundError):
_queues.get(qid)
with self.assertRaises(queues.QueueNotFoundError):
_queues.destroy(qid)

def test_not_destroyed(self):
stdout, stderr = self.assert_python_failure(
'-c',
dedent(f"""
import {_queues.__name__} as _queues
_queues.create(2, 0)
"""),
)
# It should have aborted due to an assert.
self.assertEqual(stdout, '')
self.assertNotEqual(stderr, '')

def test_bind_release(self):
with self.subTest('typical'):
qid = _queues.create(2, 0)
_queues.bind(qid)
_queues.release(qid)
self.assertEqual(get_num_queues(), 0)

with self.subTest('bind too much'):
qid = _queues.create(2, 0)
_queues.bind(qid)
_queues.bind(qid)
_queues.release(qid)
_queues.destroy(qid)
self.assertEqual(get_num_queues(), 0)

with self.subTest('nested'):
qid = _queues.create(2, 0)
_queues.bind(qid)
_queues.bind(qid)
_queues.release(qid)
_queues.release(qid)
self.assertEqual(get_num_queues(), 0)

with self.subTest('release without binding'):
stdout, stderr = self.assert_python_failure(
'-c',
dedent(f"""
import {_queues.__name__} as _queues
_queues.create(2, 0)
_queues.release(qid)
"""),
)
# It should have aborted due to an assert.
self.assertEqual(stdout, '')
self.assertNotEqual(stderr, '')


class QueueTests(TestBase):

Expand Down
5 changes: 4 additions & 1 deletion Modules/_xxinterpqueuesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,10 @@ PyDoc_STRVAR(queuesmod_create_doc,
"create(maxsize, fmt) -> qid\n\
\n\
Create a new cross-interpreter queue and return its unique generated ID.\n\
It is a new reference as though bind() had been called on the queue.");
It is a new reference as though bind() had been called on the queue.\n\
\n\
The caller is responsible for calling destroy() for the new queue\n\
before the runtime is finalized.");

static PyObject *
queuesmod_destroy(PyObject *self, PyObject *args, PyObject *kwds)
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy