@@ -112,6 +112,12 @@ def load_all(self, plugin_dir):
112112 # Load plugins asynchronously :O
113113 yield from asyncio .gather (* [self .load_plugin (path ) for path in path_list ], loop = self .bot .loop )
114114
115+ @asyncio .coroutine
116+ def unload_all (self ):
117+ yield from asyncio .gather (
118+ * [self .unload_plugin (path ) for path in self .plugins .keys ()], loop = self .bot .loop
119+ )
120+
115121 @asyncio .coroutine
116122 def load_plugin (self , path ):
117123 """
@@ -173,10 +179,10 @@ def load_plugin(self, path):
173179 self .plugins [plugin .file_name ] = plugin
174180
175181 for periodic_hook in plugin .periodic :
176- asyncio .async (self ._start_periodic (periodic_hook ))
182+ task = asyncio .async (self ._start_periodic (periodic_hook ))
183+ plugin .tasks .append (task )
177184 self ._log_hook (periodic_hook )
178185
179-
180186 # register commands
181187 for command_hook in plugin .commands :
182188 for alias in command_hook .aliases :
@@ -249,6 +255,9 @@ def unload_plugin(self, path):
249255 # get the loaded plugin
250256 plugin = self .plugins [file_name ]
251257
258+ for task in plugin .tasks :
259+ task .cancel ()
260+
252261 # unregister commands
253262 for command_hook in plugin .commands :
254263 for alias in command_hook .aliases :
@@ -502,6 +511,7 @@ def __init__(self, filepath, filename, title, code):
502511 :type filename: str
503512 :type code: object
504513 """
514+ self .tasks = []
505515 self .file_path = filepath
506516 self .file_name = filename
507517 self .title = title
0 commit comments