Accessing an attribute of a multiprocessing Proxy of a class

后端 未结 4 655
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 03:14

I have a class that I want to share in a read-only fashion with children processes in a pool, so I prepared a proxy of a class but it didn\'t work. The following is a simpli

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 04:08

    This is an example of passing parameters (example: __getitem__) or not (example: __len__):

    class TestProxy(NamespaceProxy):
        _exposed_ = ('__getattribute__', '__setattr__', '__delattr__','__len__','__getitem__')
    
        def __len__(self):
            callmethod = object.__getattribute__(self, '_callmethod')
            return callmethod('__len__')
        def __getitem__(self,index):
            callmethod = object.__getattribute__(self, '_callmethod')
            return callmethod('__getitem__',(index,))
    

提交回复
热议问题