Under review

Restart python kernel

Rupert (Moderator (EN)) 9 years ago in Scripting updated 9 years ago 2
I'm in the process of creating a series of modules that contain some handy functions to use in Micromine. In order to load the modules at the beginning of the script in Micromine I enter the following

import sys
my_folder = "D:\\Projects\\Python_Scripts"
import mm_tools as tools

It appears that the module is only imported the first time I run the script. If I make any changes to the module mm_tools then I have to shut down Micromine and then restart it. This makes debugging (which I have to do a lot) a bit annoying.

I guess (from my limited Python experience!) that I have to restart the python kernel. Is there a way to do this in Micromine without shutting down the whole program? The Ipython Notebook has a restart option. Would it be possible to add a button to the script editor that does this?

This would also be useful if running lots of memory hungry scripts in a row as it appears that I have to restart Micromine to clear the memory.
Thanks Rupert
Under review
Hello Rupert,

Yes, it is a know problem of Python. The workaround is to use imp module the following way:

import os, imp
my_folder = "D:\\Projects\\Python_Scripts"
if not my_folder in os.sys.path: os.sys.path.append(my_folder)
import mm_tools
import mm_tools as tools

This should work
Great, Thanks Pavel!
That will save me hundreds of restarts!