From ca450fb0e44fc303a2c319e2fe53920714d7551e Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 20 Dec 2015 01:47:02 -0500 Subject: [PATCH] Fix README example code. --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 92d5e9d7b..365a33ab2 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ Note that this requires `git` to be installed. ```py import discord +import asyncio client = discord.Client() @@ -76,8 +77,12 @@ def main_task(): yield from client.connect() loop = asyncio.get_event_loop() -loop.run_until_complete(main_task()) -loop.close() +try: + loop.run_until_complete(main_task()) +except Exception: + loop.run_until_complete(client.close()) +finally: + loop.close() ``` You can find examples in the examples directory.