Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have Colab reload a recently changed module on Drive

I'd like to use Google Colab as a front-end to repeatedly run code that I am developing in a .py file on my Google Drive. Specifically, I want to edit that file with e.g. vim, and have the Colab Notebook repeatedly reload my changes.

Synchronizing the file with my Drive is easy enough, as is mounting that drive and importing the module once. However, reloading the module is not.

Using either %autoreload 2 or module = importlib.reload(module)), the notebook seems to eventually react to the changed file, but very slowly and unpredictably so. Remounting the Drive appears to have no effect. Doing a "factory reset" of the notebook does seem to work, but this is unacceptably slow because I must then input a new authorization code each time to a dialogue box.

Is there any way to achieve the desired behaviour?

like image 988
AGML Avatar asked Jan 15 '20 17:01

AGML


1 Answers

I was able to do this with importlib

import some_module

import importlib
importlib.reload(some_module)
like image 122
Timmy Francesco Avatar answered Oct 07 '22 11:10

Timmy Francesco