Comments (7)
/cc
from irc3.
Might be an idea: https://pypi.python.org/pypi/stevedore
from irc3.
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.
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.
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.
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.
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)
- Hide commands from `plugins.command` HOT 4
- Handle several hosts in a configuration file HOT 3
- Builtin authentication plugin HOT 2
- builtins.LookupError: Not able to resolve HOT 2
- Add Python 3.7 to setup.py
- getaddrinfo for res in _socket.getaddrinfo error HOT 7
- irc3.plugins.logger.handler HOT 1
- KeyError: irc3.plugins.userlist in new_nick HOT 2
- iotype='out' doesn't seem to be working. HOT 3
- DCC GET seems not work HOT 6
- irc3.plugins.autojoins: join after kick delay HOT 2
- Run in a specific event loop HOT 2
- Split long messages to avoid being kicked for excess flood HOT 10
- Logger plugin not logging join event for anyone except the bot itself HOT 3
- docopt's option's description and [options] shortcut aren't working HOT 2
- Incompatibility with Python 3.10
- python 3.10 not supported HOT 1
- Support for generator-based coroutines is deprecated and is removed in Python 3.11. HOT 4
- External command output not relayed to IRC channel HOT 1
- Crtical errors
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from irc3.