From e81c4cefb418b0cfef8788f74ce3fd089e831de8 Mon Sep 17 00:00:00 2001 From: Dave Shawley Date: Wed, 19 Feb 2020 06:37:58 -0500 Subject: [PATCH] Use loop-specific create_task in Application.stop. Calling asyncio.create_task() requires a running event loop which we cannot guarantee. The event loop is not running when stop is called in the testing.SprocketsHttpTestCase. --- docs/history.rst | 7 +++++++ sprockets/http/app.py | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/history.rst b/docs/history.rst index c332b18..b82b314 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -3,6 +3,13 @@ Release History =============== +`Next Release`_ +--------------- +- :meth:`sprockets.http.app.CallbackManager.stop` no longer requires the + event loop to be running (fixes `#34`_) + +.. _#34: https://github.com/sprockets/sprockets.http/issues/34 + `2.1.0`_ (9 Oct 2019) --------------------- - Make shutdown timings configurable. diff --git a/sprockets/http/app.py b/sprockets/http/app.py index 115d03e..361c987 100644 --- a/sprockets/http/app.py +++ b/sprockets/http/app.py @@ -127,7 +127,8 @@ class CallbackManager: maybe_future = callback(self.tornado_application) if asyncio.iscoroutine(maybe_future): - maybe_future = asyncio.create_task(maybe_future) + maybe_future = io_loop.asyncio_loop.create_task( + maybe_future) if concurrent.is_future(maybe_future): shutdown.add_future(maybe_future)