当前位置: 首页>>代码示例>>Python>>正文


Python Emitter._recalculate_total_callable_outputs_recursively方法代码示例

本文整理汇总了Python中emitter.Emitter._recalculate_total_callable_outputs_recursively方法的典型用法代码示例。如果您正苦于以下问题:Python Emitter._recalculate_total_callable_outputs_recursively方法的具体用法?Python Emitter._recalculate_total_callable_outputs_recursively怎么用?Python Emitter._recalculate_total_callable_outputs_recursively使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在emitter.Emitter的用法示例。


在下文中一共展示了Emitter._recalculate_total_callable_outputs_recursively方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: EmitterSystem

# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import _recalculate_total_callable_outputs_recursively [as 别名]
class EmitterSystem(object):
    '''
    A system of emitters, representing a set of possible events in a program
    
    EmitterSystem offers a few advantages over using plain emitters.
    
    There are the `bottom_emitter` and `top_emitter`, which allow, respectively,
    to keep track of each `emit`ting that goes on, and to generate an `emit`ting
    that affects all emitters in the system.
    
    The EmitterSystem also offers a context manager, `.freeze_cache_rebuilding`.
    When you do actions using this context manager, the emitters will not
    rebuild their cache when changing their inputs/outputs. When the outermost
    context manager has exited, all the caches for these emitters will get
    rebuilt.
    '''
    # possible future idea: there is the idea of optimizing by cutting redundant
    # links between boxes. I'm a bit suspicious of it. The next logical step is
    # to make inputs and outputs abstract.
    def __init__(self):
        
        self._cache_rebuilding_frozen = 0
        self.freeze_cache_rebuilding = \
            FreezeCacheRebuildingContextManager(self)
        
        self.emitters = set()
        
        self.bottom_emitter = Emitter(self, name='bottom')
        self.emitters.add(self.bottom_emitter)
        
        self.top_emitter = Emitter(
            self,
            outputs=(self.bottom_emitter,),
            name='top',
        )
        self.emitters.add(self.top_emitter)
        
            
    def make_emitter(self, inputs=(), outputs=(), name=None):
        '''Create an emitter in this emitter system. Returns the emitter.'''

        # todo: allow one value in inputs and outputs. do in all emitter
        # constructors.
        
        inputs = set(inputs)
        inputs.add(self.top_emitter)
        outputs = set(outputs)
        outputs.add(self.bottom_emitter)
        emitter = Emitter(self, inputs, outputs, name)
        self.emitters.add(emitter)
        return emitter
    
    def remove_emitter(self, emitter):
        '''
        Remove an emitter from this system, disconnecting it from everything.
        '''
        with self.freeze_cache_rebuilding:
            emitter.disconnect_from_all()
        self.emitters.remove(emitter)
        
    def _recalculate_all_cache(self):
        '''Recalculate the cache for all the emitters.'''
        self.bottom_emitter._recalculate_total_callable_outputs_recursively()
开发者ID:,项目名称:,代码行数:65,代码来源:


注:本文中的emitter.Emitter._recalculate_total_callable_outputs_recursively方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。