Skip to content

Commit

Permalink
python: Make askpass compatible with Python 3.6
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martinpitt authored and allisonkarlitskaya committed Feb 23, 2023
1 parent 9e39cbf commit cad2e0f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/cockpit/askpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down

0 comments on commit cad2e0f

Please sign in to comment.