[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Timer scheduling and cancel-timer
From: |
Michael Heerdegen |
Subject: |
Re: Timer scheduling and cancel-timer |
Date: |
Sun, 31 Mar 2013 18:44:14 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Tomohiro Matsuyama <address@hidden> writes:
> > > (setq my-timer
> > > (run-with-timer
> > > nil 0.1
> > > (lambda ()
> > > (when my-timer
> > > (cancel-timer my-timer)
> > > (setq my-timer nil)
> > > (sit-for 0.3)))))
> > >
> > > After evaluating this code several times, you may see "zombie" timers
> > > in timer-list, though the code intends to keep at most one timer.
I see that, too.
To reveal what's happening, I ran the following experiment:
--8<---------------cut here---------------start------------->8---
(defvar my-timer nil)
(defun start-the-timer ()
(interactive)
(setq my-timer
(run-with-timer
0 0.1
(lambda ()
(cancel-timer my-timer)
(sit-for 0.3)))))
(advice-add 'timer-event-handler :before
(lambda (timer)
(when (and (eq timer my-timer)
(not (memq my-timer timer-list)))
(message "Why is this ever reached?"))))
--8<---------------cut here---------------end--------------->8---
If you call `start-the-timer', you get the message "Why is this ever
reached?" over and over.
Obviously, although the timer object created has been successfully
canceled (i.e., removed from `timer-list'), the C code still calls it
repeatedly with `timer-event-handler'. Dunno why, but that's not good.
Regards,
Michael.