Change in a python package, takes 2 runs to be updated

Hi @piac,
There is another bug that has been there on both Rhino 5 and 6.
It is similar to this one in a sense that it takes two script runs.

Whenever a change is made in Python’s package (any package similar to rhinoscriptsyntax), the change is ‘not available’ the first time I run the code from ghpython component. It takes a second run for the change to be ‘available’.
This is not the case with Rhino Python Editor, where the change is instantly ‘available’ after the first run.

Here is an example:
Create a new function ‘TestFunction’:

def TestFunc():
    print("this is a test function")

in one of modules (let’s call it “module1.py”) and save that module file.

In ghpython component, if I try to call the ‘TestFunc’:

import somecustompackage as scp
import imp
imp.reload(scp)

scp.TestFunc()

An error appears that no such function exists in ‘somecustompackage’ module.
If I try to run the script again, everything works fine, and “this is a test function” is printed to console.

I understand that the way I explained it, may not be quite clear.
But any comment on this would be appreciated.

This is code that is directly managed in the IronPython project. There is little that GhPython or Rhino.Python can do.

EDITO: Also, I think that the main reload function in Python 2.7 is reload(), not imp.reload().
Can you check with that one?

https://docs.python.org/2.7/library/functions.html#reload

Also, imp.reload docs for 3.0 state:

Other references to the old objects (such as names external to the module) are not rebound to refer to the new objects and must be updated in each namespace where they occur if that is desired.

https://docs.python.org/2.7/library/imp.html imp does not seem to contain an official reload() function.

1 Like

Hello,

What happens if you reload(somecustompackage) instead of scp, and /or maybe then scp = somecustompackage ?

1 Like

Thank you for the replies both @piac and @Dancergraham,

I tried reload() instead and reload (somecustompackage), but without success.
Interestingly now I get the same behavior (2 times run, in order for the changes to be implemented) in Rhino Python Editor as well.

I’ve used reload in the past and never experiences this. Is this a particularly complex module?

Hi @piac,
I think it is somewhat similar to rhinopythonscript.
Can I send you the files in a private message for testing?

Hi @djordje, this is really an IronPython thing: if you create a module with 1 single function, do you experience this double-reload problem?

Hi @piac,
I apologize for not replying.
Recently I started using Rhino again, and got back to this issue.

I didn’t understand the last comment. The module has tens of functions.
What would be the benefit of creating a new module with a single function?

To test if module complexity is a factor in the behavior or not.

Modules are part of a package, it is not a single,regular python module. Creating a new module with a single function inside the package, repeated two reloads issue.
With a regular (non package) module, it took only one reload. But I am not looking for this option.

Hi @djordje

at this point I’d think this is probably an IronPython issue. Maybe you could try reproducing this in its simplest form, and if it does the same, you could try posting it here: https://github.com/IronLanguages/ironpython2/issues/new

Thanks,

Giulio


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

1 Like