Git Product home page Git Product logo

Comments (11)

mostaphaRoudsari avatar mostaphaRoudsari commented on July 21, 2024

One more. Based on this post it has something to do with the order of loading libraries. I will give it a try soon.

from butterfly.

mostaphaRoudsari avatar mostaphaRoudsari commented on July 21, 2024

For now I added a force reload from this post which does the job but I need to get this fixed at some point.

def reload_package(root_module):
    package_name = root_module.__name__

    # get a reference to each loaded module
    loaded_package_modules = dict([
        (key, value) for key, value in sys.modules.items() 
        if key.startswith(package_name) and isinstance(value, types.ModuleType)])

    # delete references to these loaded modules from sys.modules
    for key in loaded_package_modules:
        del sys.modules[key]

    # load each of the modules again; 
    # make old modules share state with new modules
    for key in loaded_package_modules:
        # print 'loading %s' % key
        newmodule = __import__(key)
        oldmodule = loaded_package_modules[key]
        oldmodule.__dict__.clear()
        oldmodule.__dict__.update(newmodule.__dict__)

from butterfly.

piac avatar piac commented on July 21, 2024

I don't know. If you dig deep enough in the darkest corners of IronPython, I am not sure what you could find :) maybe something horrific :D

Is there any way you could do things more simply?

from butterfly.

piac avatar piac commented on July 21, 2024

Can you explain what you are trying to do? I am too stupid to understand this part: "re-structuring the folders when all the libraries where in the same level".

from butterfly.

piac avatar piac commented on July 21, 2024

In general, .Net types are defined by their location as well. If you load two assemblies that are a copy of each other, but from two different paths, their symbols will be different and, for example, methods accepting one type will not accept the other.

from butterfly.

mostaphaRoudsari avatar mostaphaRoudsari commented on July 21, 2024

Hi @piac. Thanks for your comments.

I'm not doing anything crazy. It's just using super for subclasses. I spent some time reading about the issue and it seems to be a common problem with super if module gets reloaded during the process.

What happens is that the id of the older version (which still exists because some other data are pointing to it) and the new version won't match and so super(subclass, self) returns False.

I couldn't recreate it in python which is easier to debug but it happens in Grasshopper/IronPython on every single run. Looks like it also frequently happens in IPython (which reloads the modules frequently). There are a couple of solutions suggested on the web but none of them worked for me except for removing the old module and force reloading it.

Disregard my comment about changing the structure. I tested and it still gives me the error. What I meant is that I moved all the files with Rhino dependencies under a separate folder and started to use relative import which I suspected is causing the issue. I was wrong though. I copied all the files back and it didn't solve the problem.

Anyways I'm good for now but it's good if at some point we can figure out what's exactly going on. That dark corners that you mentioned! :D

from butterfly.

piac avatar piac commented on July 21, 2024

I think you should investigate why this reloading happens, and under which conditions this super() call fails. This is, though, 99% a IronPython question. If one of the parent classes is a .Net class, in which case, it's still a IronPython issue, I think it might be difficult to make this work for the developers of IronPython.

I couldn't recreate it in python which is easier to debug but it happens in Grasshopper/IronPython on every single run.

Did you mean this seems not to happen in the _EditPythonScript editor?

from butterfly.

mostaphaRoudsari avatar mostaphaRoudsari commented on July 21, 2024

No I mean out of Grasshopper/Rhino just loading the libraries in python. I haven't tested it in _EditPythonScript.

from butterfly.

piac avatar piac commented on July 21, 2024

@mostaphaRoudsari Oh, I understand. Please mention me again when you are able to test there. Maybe it will help.

from butterfly.

mostaphaRoudsari avatar mostaphaRoudsari commented on July 21, 2024

Finally found the reason why this was happening. In a different GHPython component I was reloading butterfly which was causing all the issues. Now it has been fixed.
Sorry @piac! I should have double checked the components more carefully. Thank you for the support.

from butterfly.

piac avatar piac commented on July 21, 2024

Awesome, very good to know this!

from butterfly.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.