Python django.dispatch 模块,Signal() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用django.dispatch.Signal()

项目:USTC-Software-2017    作者:igemsoftware2017    | 项目源码 | 文件源码
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)