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


Python weakref.WeakKeyDictionary方法代码示例

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


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

示例1: _make_cached_stream_func

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import WeakKeyDictionary [as 别名]
def _make_cached_stream_func(src_func, wrapper_func):
    cache = WeakKeyDictionary()
    def func():
        stream = src_func()
        try:
            rv = cache.get(stream)
        except Exception:
            rv = None
        if rv is not None:
            return rv
        rv = wrapper_func()
        try:
            stream = src_func()  # In case wrapper_func() modified the stream
            cache[stream] = rv
        except Exception:
            pass
        return rv
    return func 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:_compat.py

示例2: _make_cached_stream_func

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import WeakKeyDictionary [as 别名]
def _make_cached_stream_func(src_func, wrapper_func):
    cache = WeakKeyDictionary()
    def func():
        stream = src_func()
        try:
            rv = cache.get(stream)
        except Exception:
            rv = None
        if rv is not None:
            return rv
        rv = wrapper_func()
        try:
            cache[stream] = rv
        except Exception:
            pass
        return rv
    return func 
开发者ID:jpush,项目名称:jbox,代码行数:19,代码来源:_compat.py

示例3: __init__

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import WeakKeyDictionary [as 别名]
def __init__(self, name, value=None, expected_type=None, expected_types=None, allow_none=False):
        self.name = name
        self._values = WeakKeyDictionary()

        if expected_types is not None:
            self.expected_types = expected_types
        else:
            self.expected_types = []

        if expected_type is not None:
            self.expected_types.append(expected_type)
        self.allow_none = allow_none
        self.__doc__ = "Values must be of type {0}".format(self.expected_types)

        if value is not None:
            self.validate(value)
            self.default_value = value 
开发者ID:SverkerSbrg,项目名称:openpyxl-templates,代码行数:19,代码来源:utils.py

示例4: __init__

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import WeakKeyDictionary [as 别名]
def __init__(self, clickRadius=2, moveDistance=5, parent=None):
        QtGui.QGraphicsScene.__init__(self, parent)
        self.setClickRadius(clickRadius)
        self.setMoveDistance(moveDistance)
        self.exportDirectory = None
        
        self.clickEvents = []
        self.dragButtons = []
        self.mouseGrabber = None
        self.dragItem = None
        self.lastDrag = None
        self.hoverItems = weakref.WeakKeyDictionary()
        self.lastHoverEvent = None
        self.minDragTime = 0.5  # drags shorter than 0.5 sec are interpreted as clicks
        
        self.contextMenu = [QtGui.QAction("Export...", self)]
        self.contextMenu[0].triggered.connect(self.showExportDialog)
        
        self.exportDialog = None 
开发者ID:SrikanthVelpuri,项目名称:tf-pose,代码行数:21,代码来源:GraphicsScene.py

示例5: __init__

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import WeakKeyDictionary [as 别名]
def __init__(self, providing_args=None, use_caching=False):
        """
        Create a new signal.

        providing_args
            A list of the arguments this signal can pass along in a send() call.
        """
        self.receivers = []
        if providing_args is None:
            providing_args = []
        self.providing_args = set(providing_args)
        self.lock = threading.Lock()
        self.use_caching = use_caching
        # For convenience we create empty caches even if they are not used.
        # A note about caching: if use_caching is defined, then for each
        # distinct sender we cache the receivers that sender has in
        # 'sender_receivers_cache'. The cache is cleaned when .connect() or
        # .disconnect() is called and populated on send().
        self.sender_receivers_cache = weakref.WeakKeyDictionary() if use_caching else {}
        self._dead_receivers = False 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:22,代码来源:dispatcher.py

示例6: test_trashcan_16602

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import WeakKeyDictionary [as 别名]
def test_trashcan_16602(self):
        # Issue #16602: when a weakref's target was part of a long
        # deallocation chain, the trashcan mechanism could delay clearing
        # of the weakref and make the target object visible from outside
        # code even though its refcount had dropped to 0.  A crash ensued.
        class C(object):
            def __init__(self, parent):
                if not parent:
                    return
                wself = weakref.ref(self)
                def cb(wparent):
                    o = wself()
                self.wparent = weakref.ref(parent, cb)

        d = weakref.WeakKeyDictionary()
        root = c = C(None)
        for n in range(100):
            d[c] = c = C(c)
        del root
        gc.collect() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_weakref.py

示例7: test_deepcopy_weakkeydict

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import WeakKeyDictionary [as 别名]
def test_deepcopy_weakkeydict(self):
        class C(object):
            def __init__(self, i):
                self.i = i
        a, b, c, d = [C(i) for i in xrange(4)]
        u = weakref.WeakKeyDictionary()
        u[a] = b
        u[c] = d
        # Keys aren't copied, values are
        v = copy.deepcopy(u)
        self.assertNotEqual(v, u)
        self.assertEqual(len(v), 2)
        self.assertFalse(v[a] is b)
        self.assertFalse(v[c] is d)
        self.assertEqual(v[a].i, b.i)
        self.assertEqual(v[c].i, d.i)
        del c
        self.assertEqual(len(v), 1) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_copy.py

示例8: __init__

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import WeakKeyDictionary [as 别名]
def __init__(self, queue, enqueue_ops):
        """Create a PyQueueRunner.

        When you later call the `create_threads()` method, the `QueueRunner` will
        create one thread for each op in `enqueue_ops`.  Each thread will run its
        enqueue op in parallel with the other threads.  The enqueue ops do not have
        to all be the same op, but it is expected that they all enqueue tensors in
        `queue`.

        Args:
          qnqueue_handler: a python function that transforms
          queue: A `Queue`.
          enqueue_ops: List of enqueue ops to run in threads later.
        """
        self._queue = queue
        self._enqueue_ops = enqueue_ops

        self._lock = threading.Lock()
        # A map from a session object to the number of outstanding queue runner
        # threads for that session.
        self._runs_per_session = weakref.WeakKeyDictionary() 
开发者ID:akosiorek,项目名称:hart,代码行数:23,代码来源:data_runner.py

示例9: connect

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import WeakKeyDictionary [as 别名]
def connect(self, slot, sender=None):
    if sender:
      if inspect.ismethod(slot):
        if sender not in self._methods_subs:
          self._methods_subs[sender] = weakref.WeakKeyDictionary()

        if slot.__self__ not in self._methods_subs[sender]:
          self._methods_subs[sender][slot.__self__] = set()

        self._methods_subs[sender][slot.__self__].add(slot.__func__)
      else:
        if sender not in self._functions_subs:
          self._functions_subs[sender] = weakref.WeakSet()
        self._functions_subs[sender].add(slot)
    else:
      if inspect.ismethod(slot):
        if slot.__self__ not in self._methods:
          self._methods[slot.__self__] = set()
        self._methods[slot.__self__].add(slot.__func__)
      else:
        self._functions.add(slot) 
开发者ID:bitex-coin,项目名称:backend,代码行数:23,代码来源:signals.py

示例10: connect

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import WeakKeyDictionary [as 别名]
def connect(self, s, func):
        """
        register *func* to be called when a signal *s* is generated
        func will be called
        """
        self._func_cid_map.setdefault(s, WeakKeyDictionary())
        if func in self._func_cid_map[s]:
            return self._func_cid_map[s][func]

        self._cid += 1
        cid = self._cid
        self._func_cid_map[s][func] = cid
        self.callbacks.setdefault(s, dict())
        proxy = _BoundMethodProxy(func)
        self.callbacks[s][cid] = proxy
        return cid 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:18,代码来源:cbook.py

示例11: tearDown

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import WeakKeyDictionary [as 别名]
def tearDown(self):
        signal.signal(signal.SIGINT, self._default_handler)
        unittest.signals._results = weakref.WeakKeyDictionary()
        unittest.signals._interrupt_handler = None 
开发者ID:war-and-code,项目名称:jawfish,代码行数:6,代码来源:test_break.py

示例12: __init__

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import WeakKeyDictionary [as 别名]
def __init__(self, group=None, target=None, name=None, args=(), kwargs={}):
        threading.Thread.__init__(self, group, target, name, args, kwargs)
        self._pid = None
        self._children = weakref.WeakKeyDictionary()
        self._start_called = False
        self._parent = current_process() 
开发者ID:war-and-code,项目名称:jawfish,代码行数:8,代码来源:__init__.py

示例13: __init__

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import WeakKeyDictionary [as 别名]
def __init__(self, name, dtype=None, values=None):
        self.name = name
        self.dtype = dtype or 'string'
        self.values = values
        self.value = weakref.WeakKeyDictionary() 
开发者ID:sassoftware,项目名称:python-esppy,代码行数:7,代码来源:base.py

示例14: _async_clients

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import WeakKeyDictionary [as 别名]
def _async_clients(cls):
        attr_name = '_async_client_dict_' + cls.__name__
        if not hasattr(cls, attr_name):
            setattr(cls, attr_name, weakref.WeakKeyDictionary())
        return getattr(cls, attr_name) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:7,代码来源:httpclient.py

示例15: __init__

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import WeakKeyDictionary [as 别名]
def __init__(self, value_type, offset, default, documentation):
        SpecificNamedField = type('SpecificNamedField', (NamedField,), {'__doc__': documentation})
        self._named_field = SpecificNamedField(value_type, offset, default, documentation)
        self._instance_data = WeakKeyDictionary() 
开发者ID:sixty-north,项目名称:segpy,代码行数:6,代码来源:header.py


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