Python script doesn't take into account changes during execution


#1

Hi,
just today my Python scripts started to do some strange thing.
When I run some script for the first time after restarting Rhino, it runs just fine. But when I change something in the script and try to run it again, it seems that it doesn’t take into account any changes.
I started playing with classes today, but I’m not using them in the scripts where I got these problems.
Maybe it could be problem with the namespaces?

Thanks,
Tomas

Win 7 (64-bit)
Version 5 SR8 64-bit
(5.8.40305.11495, 5.3.2014)
VM_Point_module.py (4.0 KB) VM_Point.py (433 Bytes)


Unwanted code caching on Python w/ Rhino for Mac
(Giulio Piacentino) #2

Hi Tomas

I think you mean that imported scripts are not reloaded after you change them. Is it so? If it is, there’s one reason. To speed things up, the interpreter just parses imports the first time, and then uses the previously-generated code to run the module again.

Luckily, you can use Python’s reload() function to fix this. Remember to remove that function in your final script, so that the code will not have to be regenerated every time.

I hope this is helpful.

Thanks

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com


#3

Hi Giulio,
great, thanks! That was the problem. Or at least when I now use the reload() function, it works as expected.
But still, it’s quite strange to me, because earlier I changed things in modules, that were imported and it worked just fine (at least what I can remember).

Thanks,
Tomas


(Giulio Piacentino) #4

This is part of Python. It’s not something that the Rhino editor can influence.
Maybe there was something forcing reload, but I would not know what that could be, sorry.

For sure, if you use the “Reset script engine” from the menu, this will be reloaded. But it’s not the best way, as destroying the engine has lots of consequences for the whole environment.


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com


#5

Ok, thanks again.
So reloading specific module is definitely better way then “Reset script engine” option if I get it right?

Tomas


(Giulio Piacentino) #6

Yes. The reset is really just last-resort.

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com