Disable module while running command I have a custom drush command that does some pretty heavy node creation etc. I would like to disable certain modules only for the duration of the script to improve their performance.

I can not do a drush dis module_name before running my command because I need the modules to be active on the site while the script is running, but not active for the runtime environment of the current command.

I would rather not have to hack core, but from what I can see, I'm probably going to need to alter something in either module_list() or drupal_load() since neither of them have any hooks.

Is there any way to do what I'm after without hacking core?
Here is one solution that I came up with after looking around in core's code. It seems to work as expected.

$module_list = module_list();
if (isset($module_list['token'])) {
    unset($module_list['token']);
}
// Reset the list to our new list of modules!
module_list(false, false, false, $module_list);
// Force to regenerate the stored list of hook implementations.
module_implements('', false, true);