Skip to content

Commit

Permalink
Merge pull request #210 from zhoukuncheng/refactor-async
Browse files Browse the repository at this point in the history
Simplify asyncio main loop setup
  • Loading branch information
rany2 authored Apr 12, 2024
2 parents e58af9d + e82a2d1 commit bafe5d8
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 25 deletions.
6 changes: 1 addition & 5 deletions examples/basic_audio_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,4 @@ async def amain() -> None:


if __name__ == "__main__":
loop = asyncio.get_event_loop_policy().get_event_loop()
try:
loop.run_until_complete(amain())
finally:
loop.close()
asyncio.run(amain())
6 changes: 1 addition & 5 deletions examples/basic_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,4 @@ async def amain() -> None:


if __name__ == "__main__":
loop = asyncio.get_event_loop_policy().get_event_loop()
try:
loop.run_until_complete(amain())
finally:
loop.close()
asyncio.run(amain())
6 changes: 1 addition & 5 deletions examples/dynamic_voice_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,4 @@ async def amain() -> None:


if __name__ == "__main__":
loop = asyncio.get_event_loop_policy().get_event_loop()
try:
loop.run_until_complete(amain())
finally:
loop.close()
asyncio.run(amain())
6 changes: 1 addition & 5 deletions examples/streaming_with_subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,4 @@ async def amain() -> None:


if __name__ == "__main__":
loop = asyncio.get_event_loop_policy().get_event_loop()
try:
loop.run_until_complete(amain())
finally:
loop.close()
asyncio.run(amain())
6 changes: 1 addition & 5 deletions src/edge_tts/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,7 @@ async def amain() -> None:

def main() -> None:
"""Run the main function using asyncio."""
loop = asyncio.get_event_loop_policy().get_event_loop()
try:
loop.run_until_complete(amain())
finally:
loop.close()
asyncio.run(amain())


if __name__ == "__main__":
Expand Down

0 comments on commit bafe5d8

Please sign in to comment.