本文整理汇总了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
示例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
示例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
示例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
示例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
示例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()
示例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)
示例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()
示例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)
示例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
示例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
示例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()
示例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()
示例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)
示例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()