From cad2e0f4a4bc30f10a073b0d17641f195074ed5e Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Fri, 10 Feb 2023 07:58:30 +0100 Subject: [PATCH] python: Make askpass compatible with Python 3.6 asyncio.run() and asyncio.get_running_loop() don't exist there yet. We have to actually create a shim for asyncio.get_running_loop(), as CockpitProtocol() calls it. --- src/cockpit/askpass.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cockpit/askpass.py b/src/cockpit/askpass.py index 990b353ac1b..d754d37e384 100644 --- a/src/cockpit/askpass.py +++ b/src/cockpit/askpass.py @@ -66,7 +66,13 @@ def main() -> None: sys.exit('This command must be run with stdin connected to a socket.') interaction = AuthorizeInteraction(args.prompt) - asyncio.run(interaction.run(connection)) + loop = asyncio.get_event_loop() + + # shim for Python < 3.7 + if not hasattr(asyncio, 'get_running_loop'): + asyncio.get_running_loop = lambda: loop + + loop.run_until_complete(interaction.run(connection)) if __name__ == '__main__':