From 1446386636f7290dea1cb1fd33453c30857d6cfd Mon Sep 17 00:00:00 2001 From: Lasse Blaauwbroek Date: Sun, 15 Oct 2023 12:52:32 +0200 Subject: [PATCH] Make a server fail early when the KJ loop is not running --- capnp/lib/capnp.pyx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/capnp/lib/capnp.pyx b/capnp/lib/capnp.pyx index a708846..4640d77 100644 --- a/capnp/lib/capnp.pyx +++ b/capnp/lib/capnp.pyx @@ -2403,6 +2403,9 @@ cdef class _AsyncIoStream: for `callback` will be passed directly to that function, and the server returned is similar as well. See that function for documentation on the possible arguments. """ + # Fail early in case the kj loop is not running. Without this, the error is thrown when a connection is made. + # Unless asyncio is in debug mode, that error is swallowed. + C_DEFAULT_EVENT_LOOP_GETTER() loop = asyncio.get_running_loop() return await loop.create_server(lambda: _AsyncIoStream._connect(callback), host, port, **kwargs) @@ -2417,6 +2420,9 @@ cdef class _AsyncIoStream: for `callback` will be passed directly to that function, and the server returned is similar as well. See that function for documentation on the possible arguments. """ + # Fail early in case the kj loop is not running. Without this, the error is thrown when a connection is made. + # Unless asyncio is in debug mode, that error is swallowed. + C_DEFAULT_EVENT_LOOP_GETTER() loop = asyncio.get_running_loop() return await loop.create_unix_server(lambda: _AsyncIoStream._connect(callback), path, **kwargs)