labscript-suite-temp / labscript_utils

Shared modules used by the labscript suite. Includes a graphical exception handler, debug tools, configuration management, cross platform filepath conversions, unit conversions and custom GUI widgets.
Other
0 stars 0 forks source link

Modulewatcher: ability to blacklist modules #7

Open philipstarkey opened 10 years ago

philipstarkey commented 10 years ago

Original report (archived issue) by Chris Billington (Bitbucket: cbillington, GitHub: chrisjbillington).


the ModuleWatcher class should have a method called 'blacklist', which takes a fully qualified module name as an argument.

A blacklisted module will be added, unsurprisingly, to a blacklist. Any modules that import this module will also be blacklisted. This will be achieved using an import tracer (repurposed from labscript_utils.impprof) that is set up when a ModuleWatcher is instantiated.

Blacklisted modules shouldn't be deleted from sys.modules immediately, that wouldn't make sense. They will be deleted on a method call 'clear_blacklisted' or similar.

This functionality is so that calling code can blacklist a module that it knows has import side effects and thus needs to be re-imported in code that runs repeatedly in the same interpreter, like lyse routines and labscript compilation.

So that far away code can blacklist itself, ModuleWatcher should provide access to an existing instance.

philipstarkey commented 10 years ago

Original comment by Chris Billington (Bitbucket: cbillington, GitHub: chrisjbillington).