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