Nick, unloading and loading again (not reinstalling) doesn't make a difference if I recall properly, although it's been ages since I tested. :( In essence, something hangs around in memory that says which modules have been loaded, and it won't re-read them. Somehow I suspect that the WSH-bindings (pywin32) are what make the sys.modules trick not work. But I'd need to do some serious testing to be sure.
Ah, it's not a plugin, it's a script :/ Is there an easy way to do this? I'm writing my dissertation in MC and I wouldn't want to turn scripting off and on every time I change a few lines of code, while the automatic reload on save would be pretty handy...
The "reload script file" menu item does exactly what it advertises - it reloads the script file.
To completely re-initialize the script engine you could turn scripting off, then turn it back on again.
However I found a similar problem with Lua, and with an extra line (similar to what Worstje suggested) it forced the module to be reloaded.
In case anyone is wondering, the Lua code is:
package.loaded.my_module = nil -- force reload
require "my_module"
For Python, if you can't find something similar, doesn't reloading the plugin work? That should give you a fresh copy. Failing that, delete the plugin and reinstall it. That would certainly reinitialize the script engine.
Bah, useful. From what I understood, clearing sys.modules would essentially wipe the cache of previously loaded modules, pushing Python to re-read them from disk. :/
In that case, I draw a blank for now. Sadly the issue isn't urgent enough for me to really go chase a fix down, although if I find a moment, I'll have a looker into it again.
Amended on Thu 20 Nov 2008 05:41 PM (UTC) by Worstje
Message
Take a look at my plugin MudStatus I posted a few days ago. I ran into the same problem and was too lazy to come up with a proper fix, so I pseudo-coded my way around it with the MUSHclient import directive since the plugin was small anyhow and the functionality not meant to be shared across other non-MUSHclient Pythonscripts anyhow.
However, I have since then figured (although not tested which you will need to do) that you can probably do the following to fix it (at the top of your plugin):
import sys
sys.modules = {}
I should really test to see if that theory holds, but I tend to have the habit of using the MUSHclient <import> tag anyhow because it allows me to split my triggers up also. Let us know if the above holds for you?
I have been bitten by this behaviour as well... Is there anything that can be done in MC to avoid this hackery (like restarting the interpreter whenever the script is reloaded)?
Quote: I didn't realise you could have MC triggers call functions in modules...
When you do "from module import *" it just takes every (almost every) key/value pair from the imported module's global dict and places it directly into the global dict of the importing module, so the contents of the imported module becomes the same thing as if it all was declared in the importing one. So technically speaking, you aren't calling a function in an imported module - you are calling one in the "top-level" script. Allowing the dot notation in triggers/aliases would mean allowing methods and properties access on objects, which might be a problem since different languages have different rules for doing that.
I didn't realise you could have MC triggers call functions in modules... It should be changed to allow the dot in the function name, I think, since it's valid...
import ModuleA
reload(ModuleA)
from ModuleA import *
Hypothetically, it could work since the first import results in a module object, the reload() call returns the same (or newer) module, so "from ModuleA import *", if we follow the rationale of Python's import mechanism should load the contents of the already existing object - the one that was just reloaded one line prior. No guarantees though.
If you do a "from module import *", you have to use just the function name, FunctionA. If you do "import module" you have to use module.FunctionA. I don't know if I understood what you're saying correctly.
This is neither a Python, nor a Mushclient bug. This is perfectly valid and expected behavior of Python's "import" function. When you import the same module more than once per an interpreter session, all subsequent imports result in a copy of an already compiled and loaded module being returned. It's done that way for efficiency reasons, and I personally like it - it lets me organize interaction between plugin and is extremely useful. The official way around this feature is the "reload" function that you've already found.
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.