Reputation:
I am building an IRC bot using Python. I require the bot to be extendable, and am looking to build a module system that checks modules and registers them on the fly, when the bot is running. E.g., someone with enough access could send something like "module enable feedparse" on IRC, which would search for the feedparse module in the modules/ directory. If it's there, get the full name, version and description of the module from global variables in the module itself. Then it registers and enables the module on the spot.
How would I go about doing this? Thanks!
Upvotes: 0
Views: 199
Reputation: 34718
I personally have done the following, create a manager for your modules, then run your modules as completely separate processes.
Its much better to use this "hypervisor" design than to worry about module reloading or other methods of doing the same goal. It also dodges the hot code reloading problem that can happen in python.
Much of the above can be achieved with just subprocess or the multiprocess module if you want to get truly fancy
Upvotes: 1