Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 25 lines (19 sloc) 0.956 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# Copyright (c) 2005-2009 Zooko Wilcox-O'Hearn
# This file is part of pyutil; see README.rst for licensing terms.

import warnings

# from the Twisted library
from twisted.internet import reactor

# from the pyutil library
from weakutil import WeakMethod

def callLater_weakly(delay, func, *args, **kwargs):
    """
Call func later, but if func is a bound method then make the reference it holds to object be a weak reference.

Therefore, if this scheduled event is a bound method and it is the only thing keeping the object from being garbage collected, the object will be garbage collected and the event will be cancelled.
"""
    warnings.warn("deprecated", DeprecationWarning)

    def cleanup(weakmeth, thedeadweakref):
        if weakmeth.callId.active():
            weakmeth.callId.cancel()
    weakmeth = WeakMethod(func, callback=cleanup)
    weakmeth.callId = reactor.callLater(delay, weakmeth, *args, **kwargs)
    return weakmeth
Something went wrong with that request. Please try again.