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


Python weakref.ReferenceError方法代码示例

本文整理汇总了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) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:22,代码来源:test_weakref.py

示例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) 
开发者ID:dagbldr,项目名称:dagbldr,代码行数:21,代码来源:dill.py

示例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) 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:25,代码来源:test_weakref.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_weakref.py

示例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) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:16,代码来源:test_weakref.py

示例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 
开发者ID:hexway,项目名称:apple_bleee,代码行数:16,代码来源:eveventhandler.py

示例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 
开发者ID:dagbldr,项目名称:dagbldr,代码行数:12,代码来源:dill.py

示例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) 
开发者ID:dagbldr,项目名称:dagbldr,代码行数:13,代码来源:dill.py

示例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 
开发者ID:dagbldr,项目名称:dagbldr,代码行数:11,代码来源:dill.py

示例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 
开发者ID:sassoftware,项目名称:conary,代码行数:15,代码来源:main.py


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