summaryrefslogtreecommitdiffstats
path: root/examples/asyncio-python-embed.py
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2023-12-17 10:46:44 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2023-12-17 10:46:44 +0000
commit70b47719c91522ab53abc763eb6da3b62c1a00c9 (patch)
treedb7906833e1af835fb2addf0c220f00904969cd7 /examples/asyncio-python-embed.py
parentReleasing debian version 3.0.23-3. (diff)
downloadptpython-70b47719c91522ab53abc763eb6da3b62c1a00c9.tar.xz
ptpython-70b47719c91522ab53abc763eb6da3b62c1a00c9.zip
Merging upstream version 3.0.25.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'examples/asyncio-python-embed.py')
-rwxr-xr-xexamples/asyncio-python-embed.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/examples/asyncio-python-embed.py b/examples/asyncio-python-embed.py
index 05f52f1..a8fbba5 100755
--- a/examples/asyncio-python-embed.py
+++ b/examples/asyncio-python-embed.py
@@ -19,7 +19,7 @@ loop = asyncio.get_event_loop()
counter = [0]
-async def print_counter():
+async def print_counter() -> None:
"""
Coroutine that prints counters and saves it in a global variable.
"""
@@ -29,7 +29,7 @@ async def print_counter():
await asyncio.sleep(3)
-async def interactive_shell():
+async def interactive_shell() -> None:
"""
Coroutine that starts a Python REPL from which we can access the global
counter variable.
@@ -44,13 +44,10 @@ async def interactive_shell():
loop.stop()
-def main():
- asyncio.ensure_future(print_counter())
- asyncio.ensure_future(interactive_shell())
-
- loop.run_forever()
- loop.close()
+async def main() -> None:
+ asyncio.create_task(print_counter())
+ await interactive_shell()
if __name__ == "__main__":
- main()
+ asyncio.run(main())