Skip to content

Commit 49c2e12

Browse files
author
Fabien Coelho
committed
add nogil test
1 parent d162280 commit 49c2e12

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test.py

+24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#! /usr/bin/env python
22

3+
import sys
34
import socket
45
import importlib
56
import cachetools as ct
@@ -628,3 +629,26 @@ def m1(i: int):
628629
pytest.fail("must raise an exception")
629630
except Exception as e:
630631
assert "method: bad-method" in str(e)
632+
633+
def test_nogil():
634+
635+
try:
636+
if sys._is_gil_enabled():
637+
pytest.skip("gil is enabled")
638+
except AttributeError as e:
639+
assert "_is_gil_enabled" in str(e)
640+
pytest.skip("nogil not supported")
641+
642+
assert sys.is_gil_enabled()
643+
644+
cache = ctu.StatsCache(ctu.DictCache())
645+
646+
@ctu.cached(ctu.AutoPrefixedCache(cache))
647+
def repeat(s: str, n: int) -> str:
648+
return s * n
649+
650+
assert foo("a", 3) == "aaa" and foo("a", 2) == "aa"
651+
assert foo("a", 3) == "aaa" and foo("a", 2) == "aa"
652+
assert cache.hits() == 0.5
653+
654+
assert sys.is_gil_enabled()

0 commit comments

Comments
 (0)