Code Monkey home page Code Monkey logo

Comments (7)

pypingou avatar pypingou commented on May 30, 2024

/cc

from irc3.

pypingou avatar pypingou commented on May 30, 2024

Might be an idea: https://pypi.python.org/pypi/stevedore

from irc3.

gawel avatar gawel commented on May 30, 2024

reload mean 2 things for me:

  • use new config values
  • reload python code

The first one might be easy (with help of the storage plugin)

The second one is harder. Don't know if you can keep the connection while restarting a process. It will also require to keep a "state" like channel joins an users on channel (i'm thinking of the userlist plugin)

from irc3.

pypingou avatar pypingou commented on May 30, 2024

I think people would not mind if the bot becomes unresponsive during the reload.
If it is fast enough (and that will depend of the plugin itself), the reload can probably be done without losing the connection to the irc server.

from irc3.

gawel avatar gawel commented on May 30, 2024

I came with this conclusion: there is no easy way to do that :)

What is ideally needed:

  • keep a state of data you don't want to lose (userlist)
  • keep track of asyncio.Handle you don't want to loose
  • delete all registered events
  • reload python code
  • instanciate new plugins
  • rescan events and commands

It's not possible to pickle plugins to get a current state mostly because handle objects (self.handle = loop.call_later()) are not pickable

So here is a solution: Plugins with a specific class method like PluginClass.reload(old_instance) can be reloaded. Then:

  • the python code is reloaded
  • for each plugins, we get the new plugin class and PluginClass.reload(old_instance) must return a ready to use instance of the plugin using old_instance if needed:
class UserList:

    @classmethod
    def reload(cls, old):
        new = cls(old.bot)
        new.userlist = old.userlist
        return new
  • all events are removed from the registered events
  • we rescan modules to load new commands / events / others using venusian
  • everything should be fine without losing any incoming data

Thoughts ?

from irc3.

 avatar commented on May 30, 2024

Everything sounds good to me. Also, if there is no chance that a plugin takes something else than the "bot" argument at the initialisation, we could even do:

@classmethod
def reload(cls, old, new):
    new.userlist = old.userlist
    # ...

from irc3.

gawel avatar gawel commented on May 30, 2024

It's done.

Here the interface:

class Plugin:
    def before_reload(self):
        pass
    def after_reload(self):
        pass
    @classmethod
    def reload(self, old):
        return cls(old.bot, argsifyouwant...)

All plugins are notified of before_reload/after_reload events. Only plugins with a reload method are reloaded

you can use bot.reload() or bot.reload(module,...) I guess a command can be added for that as a plugin. For now you can send a kill -HUP to the bot process.

As a bonus, bot.config is also reloaded so you can use after_reload to check/use new values

from irc3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.