Check if we're closing the event loop before using it.
Should fix #545.
This commit is contained in:
parent
6119f280c5
commit
1e1b02c630
@ -454,6 +454,9 @@ class Client:
|
|||||||
|
|
||||||
|
|
||||||
def _do_cleanup(self):
|
def _do_cleanup(self):
|
||||||
|
if self.loop.is_closed() or not self.loop.is_running():
|
||||||
|
return # we're already cleaning up
|
||||||
|
|
||||||
self.loop.run_until_complete(self.close())
|
self.loop.run_until_complete(self.close())
|
||||||
pending = asyncio.Task.all_tasks(loop=self.loop)
|
pending = asyncio.Task.all_tasks(loop=self.loop)
|
||||||
if pending:
|
if pending:
|
||||||
@ -469,6 +472,8 @@ class Client:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
self.loop.close()
|
||||||
|
|
||||||
def run(self, *args, **kwargs):
|
def run(self, *args, **kwargs):
|
||||||
"""A blocking call that abstracts away the `event loop`_
|
"""A blocking call that abstracts away the `event loop`_
|
||||||
initialisation from you.
|
initialisation from you.
|
||||||
@ -503,7 +508,6 @@ class Client:
|
|||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
self._do_cleanup()
|
self._do_cleanup()
|
||||||
self.loop.close()
|
|
||||||
|
|
||||||
# properties
|
# properties
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user