Skip to content

Descriptors not inherited on Windows #97

@Naikless

Description

@Naikless

I define a class with a custom descriptor that works very similar to a property and a method that makes use of the multiprocessing module when working with this descriptor:

class MyClass():
    
    class Descriptor:
        def __init__(self, value=None):
            self.value = value
        def __get__(self, instance, owner=None):
            return self.value
   
    @classmethod
    def init_descriptor(cls,value):
        cls.descr = cls.Descriptor(value)
    
    def __init__(self):    
        self.init_descriptor('descriptor')

    def fun(self):
        def f(x):
            return self.descr
                
        with Pool(4) as p:
            collect = list(p.imap(f, range(5)))
            p.clear()
            
        return collect

The descriptor gets initialized once an instance of that class is built. Calling MyClass().fun() returns the expected result.

Now I define a subclass:

class MySubClass(MyClass):
    def __init__(self):
        super().__init__()

While running MySubClass().descr still works as expected, MySubClass().fun() results in

AttributeError: 'MySubClass' object has no attribute 'descr'

Mind you, this issue only comes up on a Windows machine!

I have tested it with a regular property instead and they work fine, so I wonder if I have to define any other special attributes for my descriptor to get it inherited properly.

Is this even an issue with pathos.multiprocess or a flaw in the the descriptor protocol?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions