How to permanently load a module into web2py ?

47 views
Skip to first unread message

Khalil Khamlichi

unread,
Feb 18, 2017, 3:45:05 PM2/18/17
to web2py-users
Hello everyone, 
I need to query redis a lot, do I have to import redis on each request ? also I am sedning websocket messages, do I need to import websocket library on every request ? isn"t there any way to load them permanently into web2py ?

Thanks in advance.

黄祥

unread,
Feb 18, 2017, 4:01:23 PM2/18/17
to web2py-users
perhaps you can import it on models because models is executed for every requests

best regards,
stifan

Leonel Câmara

unread,
Feb 18, 2017, 4:37:36 PM2/18/17
to web2py-users
They are not imported again just because the import is there. Python and web2py's import is smart enough not to re-import a module that was already loaded unless you are using track_changes.

Anthony

unread,
Feb 18, 2017, 4:37:51 PM2/18/17
to web2py-users
It is OK to run an import statement on every request -- the Python interpreter will only import the module on the first request (per process) -- after that, it will remain in memory.

Anthony
Reply all
Reply to author
Forward
0 new messages