- or encapsulate each plugin in an independent "environment" ?
Hard to tell without knowing these plugins. Right now it sounds like that's a question only you can answer. :-)
The plugins are quite simple in fact: The Python code define a few functions like def on_value_update(x): blah blah blah return foobar and they can have global variables (if it's a problem I can forbid user's to use those global variables in their plugins). Each plugin is defined in a .py file and at runtime I load all those files, one after each other. I was reading about "scope" but I'm not sure from the documentation if it's the right solution. Can I load each of my Python files with all their functions and variables into such a "scope" and switch from one scope to another depending on the plugin I want to use ?