PDA

View Full Version : Does LW Python cache your script?



sami
01-21-2014, 09:44 PM
Another possibly dumb Python question if I may ask your kind attention:

Does LW's Python (particularly for Modeler) cache scripts? It's probably user error, but I'm getting some weirdness where I make a change in the text file and re-run it in Modeler from the Python button and I get the old error message and the new one won't run.

However, if I totally quit Modeler and re-run it, then it reflects the saved changes to the Python text file. What am I doing wrong? (these are very short simple scripts as I'm learning to rewrite my LScripts in Python - so it's not bugs in a long script) -- it would be crazy if I have to quit Modeler as I debug - surely it is something I am not getting right...?

thanks for any help!

iain_r
01-22-2014, 01:52 PM
Been having the same problem, run a script ,get an error, fix script without quiting modeler and it still uses the orignal version of the script. restart modeler and it uses the new version. Doesn't make debugging very easy. Fogbugz this and see if you get any response.

Regards

Iain

dulo
01-22-2014, 02:46 PM
That has nothing to do with Newtek, thats just the way python works. You would have to reimport the module ( your script .. ) to update it in the current python shell...
What you are asking for is more or less edit-and-continue ( because your python shell continues to run all the time in the background, no matter how often you try to start the script )
Newtek maybe could offer some mechanism to automatically reload some modules ...

sami
01-22-2014, 05:46 PM
That has nothing to do with Newtek, thats just the way python works. You would have to reimport the module ( your script .. ) to update it in the current python shell...
What you are asking for is more or less edit-and-continue ( because your python shell continues to run all the time in the background, no matter how often you try to start the script )
Newtek maybe could offer some mechanism to automatically reload some modules ...

Thanks for your reply. This is very frustrating as I have to fully quit LW everytime an error hits - but if I recall correctly - only if it gets an error. If it doesn't get an error, it seems to accept the update - which I find odd. But since I'm not intimately familiar with Python and how it handles module loading, I'm not clear on why that happens. Is there a Python command that can bypass this module caching on error?

If not can NewTek please comment on this? And fix it if possible? Even if that fix means a button which refreshes the Python without quitting Modeler. I'm worried that launching and quitting Modeler 500 times in a day is going to cause accumulated memory leaks or give me a headache down the line - I don't want to have to reboot too while debugging...

dulo
01-23-2014, 02:42 AM
Here is a link about how to handle this situation.
http://brannerchinese.wordpress.com/2012/03/03/reloading-a-python-module-after-modifying-it/
best martin

walfridson
01-23-2014, 06:54 AM
Having it cached is very useful when working on large projects. Works the same way in Maya.

Modo failed to do this...


Just have a simple launcher scripts which does reload() before firing it up...
Also make sure sys.dont_write_bytecode is True in y our case.

sami
01-23-2014, 07:09 PM
Here is a link about how to handle this situation.
http://brannerchinese.wordpress.com/2012/03/03/reloading-a-python-module-after-modifying-it/
best martin
Thanks for the link, very helpful!


Having it cached is very useful when working on large projects. Works the same way in Maya.

Modo failed to do this...


Just have a simple launcher scripts which does reload() before firing it up...
Also make sure sys.dont_write_bytecode is True in y our case.

I'll try a launcher script while debugging, thanks for the tip!

ernpchan
03-19-2014, 02:36 PM
I just encountered this caching problem in Layout. So to use reload is this what's supposed to be in the code?


import lwsdk
reload (lwsdk)