This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author thaar
Recipients
Date 2004-07-22.13:16:52
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
If i use the Timer cyclically the  memory becomes
always less.


I found following problems::

1.) The thread is not clean deleted.=>
file:threading.py  class: Thread methode:__delete

del _active[_get_ident()] only delete the thead from
the list, not the thead self.  I think the call of the
destructor of the c++ based library need a explicit del.

The problem will be fixed with following lines:

    def __delete(self):
        _active_limbo_lock.acquire()
        t=_active[_get_ident()]
        del _active[_get_ident()]
        del t
        _active_limbo_lock.release()

2.) A cyclic timer is a needed feature and it should
not use a new thread every time.

So i made following enhancement (parameter cyclic) in the 
file:threading.py  class: _Timer  

class _Timer(Thread):
    """Call a function after a specified number of seconds:

    t = Timer(30.0, f, args=[], kwargs={})
    t.start()
    t.cancel() # stop the timer's action if it's still
waiting
    """

    def __init__(self, interval, function, cyclic=0,
args=[], kwargs={}):
        Thread.__init__(self)
        self.interval = interval
        self.function = function
        self.args = args
        self.kwargs = kwargs
        self.finished = Event()
        self.cyclic= Event()
        if cyclic:
            self.cyclic.set()

    def cancel(self):
        """Stop the timer if it hasn't finished yet"""
        self.cyclic.clear()
        self.finished.set()

    def run(self):
        flag =1
        while flag:
            self.finished.wait(self.interval)
            if not self.finished.isSet():
                self.function(*self.args, **self.kwargs)
            if not self.cyclic.isSet():
                self.finished.set()
                flag = 0         



History
Date User Action Args
2007-08-23 14:24:06adminlinkissue995907 messages
2007-08-23 14:24:06admincreate