本文整理汇总了Python中weakref.ReferenceError方法的典型用法代码示例。如果您正苦于以下问题:Python weakref.ReferenceError方法的具体用法?Python weakref.ReferenceError怎么用?Python weakref.ReferenceError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weakref
的用法示例。
在下文中一共展示了weakref.ReferenceError方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_proxy_ref
# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import ReferenceError [as 别名]
def test_proxy_ref(self):
o = C()
o.bar = 1
ref1 = weakref.proxy(o, self.callback)
ref2 = weakref.proxy(o, self.callback)
del o
def check(proxy):
proxy.bar
extra_collect()
self.assertRaises(weakref.ReferenceError, check, ref1)
self.assertRaises(weakref.ReferenceError, check, ref2)
# XXX: CPython GC collects C() immediately. use ref1 instead on
# Jython
if test_support.is_jython:
self.assertRaises(weakref.ReferenceError, bool, ref1)
else:
self.assertRaises(weakref.ReferenceError, bool, weakref.proxy(C()))
self.assert_(self.cbcalled == 2)
示例2: _locate_object
# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import ReferenceError [as 别名]
def _locate_object(address, module=None):
"""get object located at the given memory address (inverse of id(obj))"""
special = [None, True, False] #XXX: more...?
for obj in special:
if address == id(obj): return obj
if module:
if PY3:
objects = iter(module.__dict__.values())
else:
objects = module.__dict__.itervalues()
else: objects = iter(gc.get_objects())
for obj in objects:
if address == id(obj): return obj
# all bad below... nothing found so throw ReferenceError or TypeError
from weakref import ReferenceError
try: address = hex(address)
except TypeError:
raise TypeError("'%s' is not a valid memory address" % str(address))
raise ReferenceError("Cannot reference object at '%s'" % address)
示例3: test_proxy_ref
# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import ReferenceError [as 别名]
def test_proxy_ref(self):
o = C()
o.bar = 1
ref1 = weakref.proxy(o, self.callback)
ref2 = weakref.proxy(o, self.callback)
del o
gc.collect()
def check(proxy):
proxy.bar
self.assertRaises(weakref.ReferenceError, check, ref1)
self.assertRaises(weakref.ReferenceError, check, ref2)
# Need to add extra step for Jython - in the orginal test, ref counting had already removed C()
# self.assertRaises(weakref.ReferenceError, bool, weakref.proxy(C()))
o2 = C()
ref3 = weakref.proxy(o2)
del o2
extra_collect()
self.assertRaises(weakref.ReferenceError, bool, ref3)
self.assertTrue(self.cbcalled == 2)
示例4: test_proxy_ref
# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import ReferenceError [as 别名]
def test_proxy_ref(self):
o = C()
o.bar = 1
ref1 = weakref.proxy(o, self.callback)
ref2 = weakref.proxy(o, self.callback)
del o
def check(proxy):
proxy.bar
self.assertRaises(weakref.ReferenceError, check, ref1)
self.assertRaises(weakref.ReferenceError, check, ref2)
self.assertRaises(weakref.ReferenceError, bool, weakref.proxy(C()))
self.assertEqual(self.cbcalled, 2)
示例5: test_proxy_ref
# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import ReferenceError [as 别名]
def test_proxy_ref(self):
o = C()
o.bar = 1
ref1 = weakref.proxy(o, self.callback)
ref2 = weakref.proxy(o, self.callback)
del o
def check(proxy):
proxy.bar
self.assertRaises(weakref.ReferenceError, check, ref1)
self.assertRaises(weakref.ReferenceError, check, ref2)
self.assertRaises(weakref.ReferenceError, bool, weakref.proxy(C()))
self.assertTrue(self.cbcalled == 2)
示例6: handle_event
# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import ReferenceError [as 别名]
def handle_event(self, event):
"return True if the event was handled. Return False if the application should stop sending this event."
if event.name not in self.event_handlers:
return False
else:
remove_list = []
for handler in self.event_handlers[event.name]:
try:
handler(event)
except weakref.ReferenceError:
remove_list.append(handler)
for dead_handler in remove_list:
self.event_handlers[event.name].remove(handler)
return True
示例7: ndarraysubclassinstance
# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import ReferenceError [as 别名]
def ndarraysubclassinstance(obj):
try: # check if is ndarray, and elif is subclass of ndarray
if getattr(obj, '__class__', type) is NumpyArrayType: return False
elif not isinstance(obj, NumpyArrayType): return False
except ReferenceError: return False # handle 'R3' weakref in 3.x
# verify that __reduce__ has not been overridden
NumpyInstance = NumpyArrayType((0,),'int8')
if id(obj.__reduce_ex__) == id(NumpyInstance.__reduce_ex__) and \
id(obj.__reduce__) == id(NumpyInstance.__reduce__): return True
return False
示例8: save_dictproxy
# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import ReferenceError [as 别名]
def save_dictproxy(pickler, obj):
log.info("Dp: %s" % obj)
attr = obj.get('__dict__')
#pickler.save_reduce(_create_dictproxy, (attr,'nested'), obj=obj)
if type(attr) == GetSetDescriptorType and attr.__name__ == "__dict__" \
and getattr(attr.__objclass__, "__dict__", None) == obj:
pickler.save_reduce(getattr, (attr.__objclass__,"__dict__"),obj=obj)
return
# all bad below... so throw ReferenceError or TypeError
from weakref import ReferenceError
raise ReferenceError("%s does not reference a class __dict__" % obj)
示例9: save_weakproxy
# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import ReferenceError [as 别名]
def save_weakproxy(pickler, obj):
refobj = _locate_object(_proxy_helper(obj))
try: log.info("R2: %s" % obj)
except ReferenceError: log.info("R3: %s" % sys.exc_info()[1])
#callable = bool(getattr(refobj, '__call__', None))
if type(obj) is CallableProxyType: callable = True
else: callable = False
pickler.save_reduce(_create_weakproxy, (refobj, callable), obj=obj)
return
示例10: __closeCursors
# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import ReferenceError [as 别名]
def __closeCursors(self, doclose=0):
"""__closeCursors() - closes all cursors associated with this connection"""
if self.__anyCursorsLeft():
cursors = map(lambda x: x(), self.cursors.data.values())
for cursor in cursors:
try:
if doclose:
cursor.close()
else:
cursor._reset()
except weakref.ReferenceError:
pass