Skip to content

Commit e841928

Browse files
committed
Properly cancel periodic hooks when unloading a plugin
1 parent 93331b4 commit e841928

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

cloudbot/plugin.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ def load_plugin(self, path):
173173
self.plugins[plugin.file_name] = plugin
174174

175175
for periodic_hook in plugin.periodic:
176-
asyncio.async(self._start_periodic(periodic_hook))
176+
task = asyncio.async(self._start_periodic(periodic_hook))
177+
plugin.tasks.append(task)
177178
self._log_hook(periodic_hook)
178179

179-
180180
# register commands
181181
for command_hook in plugin.commands:
182182
for alias in command_hook.aliases:
@@ -249,6 +249,9 @@ def unload_plugin(self, path):
249249
# get the loaded plugin
250250
plugin = self.plugins[file_name]
251251

252+
for task in plugin.tasks:
253+
task.cancel()
254+
252255
# unregister commands
253256
for command_hook in plugin.commands:
254257
for alias in command_hook.aliases:
@@ -502,6 +505,7 @@ def __init__(self, filepath, filename, title, code):
502505
:type filename: str
503506
:type code: object
504507
"""
508+
self.tasks = []
505509
self.file_path = filepath
506510
self.file_name = filename
507511
self.title = title

0 commit comments

Comments
 (0)