python类Signal()的实例源码

base.py 文件源码 项目:USTC-Software-2017 作者: igemsoftware2017 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def register(self, key, func):
        """
        Registration.

        For a specific registry instance, a function can only be registered
        ONCE, otherwise a KeyError will be raised.
        """

        if hasattr(func, self.func_property_name):
            raise KeyError('Function %r has been registered.' % func)

        if key not in self.signal_mapping:
            self.signal_mapping[key] = Signal(providing_args=self.providing_args)  # noqa

        # The receiver function to be connected to a signal
        def _receiver(sender, **kwargs):
            args = (kwargs.get(k, None) for k in self.providing_args)
            func(*args)

        # Attach the receiver onto the function to avoid garbage collection.
        setattr(func, self.func_property_name, (key, _receiver))
        self.signal_mapping[key].connect(_receiver)

        self.perform_register(key, func)


问题


面经


文章

微信
公众号

扫码关注公众号