Why would new code be ignored and old code be executed?

76 views
Skip to first unread message

Andrew Rogers

unread,
Mar 5, 2020, 8:49:33 AM3/5/20
to web2py-users
Everything has been good for days. But I have had this happen multiple times in the last few hours. I make changes to a module or controller file, save it, refresh the app but the old code still runs. I was working in both the IDE that comes with web2py and Visual Studio Code.

I eventually found that i can use the 'Remove Compiled' menu option which i assume forces a recompile of somethings - I think that helps most times. Sometimes the menu option is not available so i have to first use the 'Compile' menu option then the 'Remove Compiled'.

I also tried stopping and starting the server (on Windows). And clearing the cache and what not. It seemed to start happening after i added a module that held code used by a table definition to COMPUTE a field value.

Anyhow, i am not looking for a specific answer to my problem. I would just like to understand how the compiling of code works and what can cause this sort of problem (is this normal? have i probably done something stupid? is there a better way to fix these issues?). I have googled a lot but didn't really get much insight into this issue and web2py specifically.

Thanks


Val K

unread,
Mar 5, 2020, 4:05:27 PM3/5/20
to web2py-users
To track module changes try this


from gluon.custom_import import track_changes; track_changes(True)

Also, your problem looks like you have more then one web2py server running

Andrew Rogers

unread,
Mar 6, 2020, 4:38:31 AM3/6/20
to web2py-users
Thanks for your advice Val. I will try your suggestion... and google search a little to see what it does

I dont think i had two servers running but i will look out  for that in the future.

It seems that the Module i added was the main problem. I moved all the code into the Controller and didnt have any more issues. I dont know what best practice is but from a few things i read it seemed to discourage using Modules.

Carlos Correia

unread,
Mar 6, 2020, 4:48:14 AM3/6/20
to web...@googlegroups.com
Às 09:38 de 06/03/20, Andrew Rogers escreveu:
Thanks for your advice Val. I will try your suggestion... and google search a little to see what it does

I dont think i had two servers running but i will look out  for that in the future.

It seems that the Module i added was the main problem. I moved all the code into the Controller and didnt have any more issues. I dont know what best practice is but from a few things i read it seemed to discourage using Modules.

Code in the modules folder are compiled automatically when the python file is first invoked. So, after you change any file in modules, you should remove the correspondent .pyc file.

In controllers and models, however the files are not compiled by default, so, most likely, there are no compiled files in those folders and the code is interpreted at every request.


On Friday, 6 March 2020 07:05:27 UTC+10, Val K wrote:
To track module changes try this


from gluon.custom_import import track_changes; track_changes(True)

Also, your problem looks like you have more then one web2py server running


Regards,

Carlos Correia
=========================
MEMÓRIA PERSISTENTE
GSM:  917 157 146
e-mail: ge...@memoriapersistente.pt
URL: http://www.memoriapersistente.pt
XMPP (Jabber): car...@memoriapersistente.pt
GnuPG: wwwkeys.eu.pgp.net

AGRogers

unread,
Mar 6, 2020, 5:08:44 AM3/6/20
to web...@googlegroups.com
>>>  Code in the modules folder are compiled automatically when the python file is first invoked. So, after you change any file in modules, you should remove the correspondent .pyc file.

Ah, i see, Thanks for the tip.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/2972294b-9cfb-cc26-356d-ea9ec97c99fa%40memoriapersistente.pt.

Val K

unread,
Mar 6, 2020, 11:01:35 AM3/6/20
to web2py-users
oh yeah, it is definitely due to you press compile in appadmin, it is intended for production. Dont compile app while you develop. I use modules without any issues with tracking as i mentoined above

Andrew Rogers

unread,
May 1, 2020, 7:55:36 AM5/1/20
to web2py-users
Hi again

I am having a similar problem again. I havent compiled the app - i have learnt from that mistake, thanks.

I am now trying to import some of my custom functions from other python files in the same app. After i got an __init.py__ file in place i was able to see and use my imported functions.

However, now when i make a change to the imported function, the new code is ignored. I step through line by line in Visual Studio Code and can see it 'process' my new code but it is running the old line.

I can 'fix' the problem 
1. by restarting the server - but it is only fixed until i make another change which is then ignored.
2. by removing 'from common_functions import DetermineMediaRepresentation' - it just uses the web2py magic to find the function

'common_functions.py' lives in the 'models' folder, not the 'modules' folder.

Can anyone tell me what i am doing wrong?

PS: The reason for the change to explicitly importing was that i wanted to just right-click the function in VSC and choose 'Go to Definition'. If i dont explicitly import then VSC doesnt know where my functions are and I have to go find them by hand.
Reply all
Reply to author
Forward
0 new messages