From 6d5175ad9aee4cf71bb268d062dfb27904390b3b Mon Sep 17 00:00:00 2001 From: Rapptz Date: Fri, 8 Jan 2016 13:29:33 -0500 Subject: [PATCH] Document how Client.run should be the last function to call. --- discord/client.py | 7 +++++++ docs/migrating.rst | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/discord/client.py b/discord/client.py index 5c979128d..4c06dcbf4 100644 --- a/discord/client.py +++ b/discord/client.py @@ -759,7 +759,14 @@ class Client: # cancel all tasks lingering finally: loop.close() + + Warning + -------- + This function must be the last function to call due to the fact that it + is blocking. That means that registration of events or anything being + called after this function call will not execute until it returns. """ + try: self.loop.run_until_complete(self.start(email, password)) except KeyboardInterrupt: diff --git a/docs/migrating.rst b/docs/migrating.rst index caf15d674..2cfa2bc62 100644 --- a/docs/migrating.rst +++ b/docs/migrating.rst @@ -262,6 +262,13 @@ After: client.run('email', 'password') +.. warning:: + + Like in the older ``Client.run`` function, the newer one must be the one of + the last functions to call. This is because the function is **blocking**. Registering + events or doing anything after :meth:`Client.run` will not execute until the function + returns. + This is a utility function that abstracts the event loop for you. There's no need for the run call to be blocking and out of your control. Indeed, if you want control of the event loop then doing so is quite straightforward: