human
Solve the following python programming problem given the following code:
@skip('silverlight')
def test_event_lifetime():
assistant
#Here is the Python code you requested.

    """ensures that circular references between an event on an instance
    and the handling delegate don\t call leaks and don\t release too soon
    """
    def keep_alive(o):
        pass
    def test_runner():
        import _weakref
        global called
        called = 0
        a = IronPythonTest.Events()
        def foo():
            global called
            called += 1
        foo.abc = a
        a.InstanceTest += foo
        a.CallInstance()
        AreEqual(called, 1)
        ret_val = _weakref.ref(foo)
        keep_alive(foo)
        import gc
        for i in xrange(10):
            gc.collect()
        a.CallInstance()
        AreEqual(called, 2)
        return ret_val
    func_ref = test_runner()
    import gc
    for i in xrange(10):
        gc.collect()
    Assert((not hasattr(func_ref, 'abc')))
    AreEqual(func_ref(), None)
    AreEqual(called, 2)