From 6ef03b852aa81c5a867ba934eb99a9590f94a32b Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Wed, 3 Aug 2022 00:34:48 +0100 Subject: [PATCH 1/3] enable the cython binding=True directive it becomes the default in cython3 and is needed for sniffio to detect uvloop as asyncio efficiently --- tests/test_base.py | 10 ++++++++++ uvloop/loop.pxd | 2 +- uvloop/loop.pyx | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/test_base.py b/tests/test_base.py index ef8feb2a..a31cf2aa 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -598,6 +598,16 @@ async def coro(): self.loop.set_task_factory(None) self.assertIsNone(self.loop.get_task_factory()) + def test_asyncgen_hooks(self): + async def get_asyncgens(): + return sys.get_asyncgen_hooks() + + # for sniffio to detect uvloop as asyncio efficiently the running loop + # call_soon module needs to match the asyncgen_hooks module + hooks = self.loop.run_until_complete(get_asyncgen_hooks) + self.assertEqual(hooks.finzalier.__module__, "uvloop.loop") + self.assertEqual(self.loop.call_soon.__module__, "uvloop.loop") + def test_shutdown_asyncgens_01(self): finalized = list() diff --git a/uvloop/loop.pxd b/uvloop/loop.pxd index 06bee851..740f67e9 100644 --- a/uvloop/loop.pxd +++ b/uvloop/loop.pxd @@ -1,4 +1,4 @@ -# cython: language_level=3 +# cython: language_level=3, embedsignature=True, binding=True from .includes cimport uv diff --git a/uvloop/loop.pyx b/uvloop/loop.pyx index d9b5aaac..0438ed8b 100644 --- a/uvloop/loop.pyx +++ b/uvloop/loop.pyx @@ -1,4 +1,4 @@ -# cython: language_level=3, embedsignature=True +# cython: language_level=3, embedsignature=True, binding=True import asyncio cimport cython From 9f4c036d22a0f084d8ca05d1a3333f8e7494cf77 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Wed, 3 Aug 2022 00:36:27 +0100 Subject: [PATCH 2/3] Update tests/test_base.py --- tests/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_base.py b/tests/test_base.py index a31cf2aa..7bd50ee1 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -605,7 +605,7 @@ async def get_asyncgens(): # for sniffio to detect uvloop as asyncio efficiently the running loop # call_soon module needs to match the asyncgen_hooks module hooks = self.loop.run_until_complete(get_asyncgen_hooks) - self.assertEqual(hooks.finzalier.__module__, "uvloop.loop") + self.assertEqual(hooks.finalizer.__module__, "uvloop.loop") self.assertEqual(self.loop.call_soon.__module__, "uvloop.loop") def test_shutdown_asyncgens_01(self): From f62adf9a03319765248f85c6139d8b4289f17de2 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Wed, 3 Aug 2022 00:42:21 +0100 Subject: [PATCH 3/3] Update tests/test_base.py --- tests/test_base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_base.py b/tests/test_base.py index 7bd50ee1..bfb23ad1 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -599,12 +599,12 @@ async def coro(): self.assertIsNone(self.loop.get_task_factory()) def test_asyncgen_hooks(self): - async def get_asyncgens(): - return sys.get_asyncgen_hooks() + async def acall(fn): + return fn() # for sniffio to detect uvloop as asyncio efficiently the running loop # call_soon module needs to match the asyncgen_hooks module - hooks = self.loop.run_until_complete(get_asyncgen_hooks) + hooks = self.loop.run_until_complete(acall(sys.get_asyncgen_hooks)) self.assertEqual(hooks.finalizer.__module__, "uvloop.loop") self.assertEqual(self.loop.call_soon.__module__, "uvloop.loop")