sopel-irc / sopel

:robot::speech_balloon: An easy-to-use and highly extensible IRC Bot framework. Formerly Willie.
https://sopel.chat
Other
950 stars 402 forks source link

reload: error with plugin whose file has moved #1761

Open dgw opened 4 years ago

dgw commented 4 years ago

Upon realizing I had a reddit.py in /var/lib/sopel/modules that shadowed the built-in one (preventing me from seeing the effects of edits to it), I deleted the outdated file and attempted to reload reddit so I could get on with debugging & testing the issue at hand:

[2019-11-23 01:33:33,719] sopel.bot            INFO     - Unloaded plugin reddit
[2019-11-23 01:33:33,720] sopel.bot            ERROR    - Unexpected error ([Errno 2] No such file or directory: '/var/lib/sopel/modules/reddit.py') from dgw at 2019-11-23 01:33:33.719968. Message was: Kaede: reload reddit
Traceback (most recent call last):
  File "/home/dgw/sopel-dev/sopel/bot.py", line 533, in call
    exit_code = func(sopel, trigger)
  File "/home/dgw/sopel-dev/sopel/module.py", line 567, in guarded
    return function(bot, trigger, *args, **kwargs)
  File "/home/dgw/sopel-dev/sopel/modules/reload.py", line 48, in f_reload
    bot.reload_plugin(name)
  File "/home/dgw/sopel-dev/sopel/bot.py", line 257, in reload_plugin
    plugin.reload()
  File "/home/dgw/sopel-dev/sopel/plugins/handlers.py", line 370, in reload
    self._module = self._load()
  File "/home/dgw/sopel-dev/sopel/plugins/handlers.py", line 342, in _load
    with open(self.path) as mod:
FileNotFoundError: [Errno 2] No such file or directory: '/var/lib/sopel/modules/reddit.py'

Note that immediately saying Kaede: load reddit worked just fine. Clearly the plugin system can adapt, but maybe there's a race condition?

I've only seen this with a single-file plugin, but that's only because my Sopel bot doesn't have any directory-based plugins (I avoid writing them because of other known reloading problems). Presumably it affects any plugin, if the type changes (e.g. from a file in .sopel/modules to a submodule in sopel.modules.*)? Needs more testing, though preferably not at almost 01:00 local time. 😁

Assigning to the crazy Frenchman who wrote the new plugin handlers, since he'll be able to figure out where to start debugging faster than anyone else. 😛

dgw commented 4 years ago

Punted, per IRC. This will allow time for Exirel to develop a better solution, without starting with a kludge first.

Exirel commented 4 years ago

Months later, and I'm still not sure how to fix that exactly.

Exirel commented 3 years ago

Yup, year later, still no idea how to approach that properly.

dgw commented 3 years ago

Let's revisit this after we drop old Python crap for 8.0. If enough EOL Python versions go away, this might be simpler.

dgw commented 3 years ago

Here again from the future, musing that #1695 is kind of related.

dgw commented 2 years ago

Going along with the other plugin-related wishlist stuff. Not sure when this might get worked on, but it remains a wishlist item and I would like to look at it again after 8.0.