Suppose my web2py app is stored at ~/web2py/applications/myweb2pyapp
Instead making local_import("model") for a model stored at myweb2pyapp/
models/model.py, i need to make the same statement for a model stored
at ~/another/path/module.py
Is that possible? Note that i do not really know what local_import
does but i been told that it is required to update a modified module
without web server restart.
Thank you
I meant import modules, sorry for the mistake.
So to import a module from another path i could do:
from gluon.custom_import import track_changes
track_changes(True)
sys.path.append("another/path")
Thank you Anthony
Thanks again for the support
On Dec 2, 2:04 am, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:
" ... In any multi-threaded Python program (and not only Python) you
should not use os.chdir and you should not change sys.path when you
have more than one thread running. It is not safe because it affects
other threads. Moreover you should not sys.path.append() in a loop
because it may explode.
All web frameworks are multi-threaded and requests are executed in a
loop. Some web frameworks do not allow you to install/un-install
applications without restarting the web server and therefore IF
os.chdir/sys.path.append are only executed at startup then there is no
problem.
In web2py we want to be able to install/uninstall applications without
restarting the web server. We want apps to be very dynamical (for
example define models based on information provided with the http
request). We want each app to have its own models folder and we want
complete separation between apps so that if two apps need to different
versions of the same module, they do not conflict with each other, so
we provide APIs to do so (request.folder, local_import).
You can still use the normal os.chdir and sys.path.append but you
should do it outside threads (and this is not a web2py specific
issue). You can use import anywhere you like as you would in any other
Python program.
I strongly suggest moving this discussion to the web2py mailing
list. ..."
How about an extrapaths file stored somewhere inside the application
folder?
import sys
sys.path.append(...)
that file is executed only once.
Thanks
On Dec 2, 6:50 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>