當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。