user775171
user775171

Reputation:

Creating module manager using Python?

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

Answers (1)

Jakob Bowyer
Jakob Bowyer

Reputation: 34718

I personally have done the following, create a manager for your modules, then run your modules as completely separate processes.

  • That way reloading a process is as simple as killing and running it
  • shutting down and starting is simple
  • and so is error handling because you can just pipe stderr to the irc channel.
  • You also have the advantage of being able to load new modules without halting the bot or fighting pythons import mechanics

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

Related Questions