Why do you use __import__(class2) instead of import class2
If you do the latter, does track changes work? On Wednesday, 12 December 2012 01:33:41 UTC-6, Chr_M wrote: > > Python 2.7.3 > Web2py 2.2.1 > > The situation: > > In modules directory I have a subdirectory with two files class1.py and > class2.py. This is a package (empty __init__.py is present). class2.py > imports class1.py and Class2 inherits from Class1. My controller > dynamically imports class2 with the function __import__(class2). On top of > my db.py model I call the track_changes part. The modules do not seem to be > updated if I change code in class1.py or class2.py. > > I have solved it for now by reloading all the modules with reload() after > I import them. So after I dynamically import class2 in my controller I call > reload(class2). In class2.py after the import of class1 I call > reload(class1). This is the only way I get the code changes to work in both > files. > > It seems that the track_changes part is not working in this situation or > something? Or is there another solution? > > Regards, Chris > > > On Monday, December 10, 2012 4:34:33 PM UTC+1, Massimo Di Pierro wrote: >> >> It should work when you do it. >> >> Which python version? Which web2py version? >> >> On Monday, 10 December 2012 02:57:20 UTC-6, Chr_M wrote: >>> >>> I call this function at the top of my db.py model file. Is this not the >>> correct location? >>> >>> Regards, Chris >>> >>> >>> On Sunday, December 9, 2012 11:55:06 PM UTC+1, Massimo Di Pierro wrote: >>>> >>>> This has come up before. >>>> >>>> from gluon.custom_import import track_changes; track_changes() >>>> >>>> must be a model file, before the modules are imported, not in the >>>> modules themselves which are otherwise cached and therefore the line may >>>> or >>>> may not be executed. >>>> >>>> Massimo >>>> >>>> On Sunday, 9 December 2012 15:34:09 UTC-6, Chr_M wrote: >>>>> >>>>> Sometimes the changes in the code of a module (in the modules >>>>> directory) are not working when requesting the url that uses these >>>>> modules. >>>>> in the modules directory I have a subdirectory with python files that >>>>> form >>>>> a package (__init__.py file in this subdirectory). I have added >>>>> >>>>> from gluon.custom_import import track_changes >>>>> track_changes() >>>>> >>>>> in the first model that gets called, but still sometimes code changes >>>>> are not working. I noticed that the py-files in the modules dir get >>>>> compiled to pyc-files. But at one point (it looks to be randomly) these >>>>> are >>>>> not compiled anymore when I change code in the py-files. But even when I >>>>> remove these pyc-files, the code changes are still not working when >>>>> requesting the url. >>>>> >>>>> Am I missing something? Is there a cache I can clear or something? I >>>>> now have to restart web2py to make the code changes work... >>>>> >>>>> Thanks. >>>>> >>>>> Regards, Chris >>>>> >>>>> --

