guidoschmidt / circadian.el

Theme-switching for Emacs based on daytime
https://guidoschmidt.github.io/circadian.el
MIT License
175 stars 8 forks source link

Emacs is freezed at switch #28

Closed follow39 closed 5 months ago

follow39 commented 1 year ago

Hello! I have a problem - Emacs is completely freezed while swithing process. Theme is swithed but Emacs doesn't respond at all.

Related config:

(use-package ef-themes
  :straight (:host github :repo "protesilaos/ef-themes")
  :defer)

(use-package circadian
  :straight (:host github :repo "guidoschmidt/circadian.el")
  :requires (local-config)
  :custom
  ;; (circadian-themes '(("7:30" . ef-light)
  ;;                     ("19:30" . ef-night)))
  (calendar-latitude 44.786568)
  (calendar-longitude 20.448921)
  (circadian-themes '((:sunrise . ef-light)
                      (:sunset  . ef-night)))
  :config
  (circadian-setup))

Full config

  1. GNU Emacs 29.0.90 (build 1, aarch64-apple-darwin22.4.0, NS appkit-2299.50 Version 13.3.1 (a) (Build 22E772610a)) of 2023-05-04 MacOS 13.4.1 (22F82) Circadian: 52e336d9bb66cfd6d6dc5b9213ea21796ac873d4 Ef-themes: 27bf0ff4d9218c382fbaa512efb754f19b667678
  2. GNU Emacs 29.0.91 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) of 2023-06-04 Ubuntu 20.04.6 LTS Circadian: 52e336d9bb66cfd6d6dc5b9213ea21796ac873d4 Ef-themes: 27bf0ff4d9218c382fbaa512efb754f19b667678
DerGuteMoritz commented 1 year ago

Same here. When it happens, the process is spinning with 100% CPU utlization.

guidoschmidt commented 11 months ago

Hey thanks for reporting, unfortunatelly I'm tend to get behind maintaining circadian.el. If one of you feels keen enough to debug this, it would be highly appreciated.

meedstrom commented 7 months ago

Mine didn't freeze, but Emacs was super-slow for a while.

I caught the reason with a profiler (so nice to have the profiler on a hotkey!): 57% CPU on timer-event-handler calling circadian-activate-latest-theme. Repeatedly, I assume.

When Emacs was snappy again, I noted the time was 18:01. So perhaps it keeps running for the whole minute?

Test specifying the time as 18:00:00 instead of just 18:00.

meedstrom commented 7 months ago

I found something interesting, it seems that Emacs' run-at-time function, passed "18:00" will run right away even if it is now 18:00:59!

That may or may not be related.

If it is, the source of the error must be that circadian is re-scheduling the same theme until the clock is definitely greater. I propose changing the little <= inside circadian-a-earlier-b-p to a <. I haven't tested if that makes a difference yet. I don't always get the bug in the first place, so it'd be good if someone else can say if it makes a difference.

xeechou commented 7 months ago

same here. It's cause huge issue in CPU usage on windows.

divyaranjan1905 commented 5 months ago

Hey thanks for reporting, unfortunatelly I'm tend to get behind maintaining circadian.el. If one of you feels keen enough to debug this, it would be highly appreciated.

If you haven't been able to maintain the package, would you mind if I step up as a maintainer? I've been using this package for almost more than an year and would rather not let this die.

guidoschmidt commented 5 months ago

@divyaranjan1905 happy to accept pull requests or even simple findings here in the ticket. I'm just updating my Windows Emacs to 29.3 now and will test a bit + see how it behaves on my Macbook.

guidoschmidt commented 5 months ago

I found something interesting, it seems that Emacs' run-at-time function, passed "18:00" will run right away even if it is now 18:00:59!

That may or may not be related.

If it is, the source of the error must be that circadian is re-scheduling the same theme until the clock is definitely greater. I propose changing the little <= inside circadian-a-earlier-b-p to a <. I haven't tested if that makes a difference yet. I don't always get the bug in the first place, so it'd be good if someone else can say if it makes a difference.

Ok changing this to < only here https://github.com/guidoschmidt/circadian.el/blob/06f3cda8bc934c4806f403d628c169a94a8bed31/circadian.el#L105 let the tests fail, so that's clearly not the right thing unfortunatelly.

I also couldn't yet reproduce high CPU usage on my macOS system 😢 ... I think we first need to find a reliable way to reproduce this bug (+ which Emacs version on which OS)

guidoschmidt commented 5 months ago

Indeed it looks like circadian-activate-latest-theme is running for a whole minute. A simple print statement illustrates it 95e934fce4af7042e00c5c04f2da7c76d20ce6f4 quite easily.

madanyang commented 5 months ago

Your last release reintroduced the freeze with Emacs 29.3. Other than using a kill command, nothing is possible via Emacs mini buffer. There is a continues update about the next run time in the minibuffer making it unusable.

meedstrom commented 5 months ago

It does not freeze for me. Emacs 30.0.50. Although it does complain about calendar-latitude and longitude, even though my circadian-themes sets the times explicitly, so I set latitude and longitude too.