Skip to content
1 change: 1 addition & 0 deletions Lib/asyncio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,6 @@ def interrupt(self) -> None:
else:
break

loop.close()
console.write('exiting asyncio REPL...\n')
sys.exit(return_code)
14 changes: 14 additions & 0 deletions Lib/test/test_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,20 @@ def test_toplevel_contextvars_async(self):
expected = "toplevel contextvar test: ok"
self.assertIn(expected, output, expected)

def test_loop_was_closed(self):
user_input = dedent("""\
import atexit
atexit.register(\
lambda loop: print("loop closed:", loop.is_closed()),\
asyncio.get_running_loop(),\
)
""")
Comment thread
johnslavik marked this conversation as resolved.
Outdated
p = spawn_asyncio_repl()
p.stdin.write(user_input)
output = kill_python(p)
self.assertEqual(p.returncode, 0)
self.assertIn("loop closed: True", output)


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The asyncio REPL now properly closes the loop upon the end of interactive session.
Comment thread
johnslavik marked this conversation as resolved.
Outdated
Previously, it could cause surprising warnings.
Contributed by Bartosz Sławecki.
Loading