2

Ok, this issue I'm running into seems pretty weird. I'm running an async process during init and I have set a process sentinel to tell me when it exits. This works fine in terminal Emacs but in GUI Emacs the process sentinel never runs.

Here is a minimal working example:

(setq my/test-flag nil)
(defun my/test-sentinel (proc &optional _change)
  (setq my/test-flag t))
(let* ((name "test")
       (buf (generate-new-buffer (concat "*" name "*")))
       (proc (let ((process-connection-type nil))
               (apply #'start-process name buf "sleep" '("3")))))
  (set-process-sentinel proc #'my/test-sentinel)
  (while (not my/test-flag)
    (sleep-for 0.05)))

If you put this in init.el and run terminal Emacs, it will hang for 3 seconds as expected before continuing on. GUI Emacs, on the other hand, will hang forever, indicating that my/test-sentinel is never run, even though the process does finish after 3 seconds.

Background info:

  • I am using Emacs 27.1 from the Arch Linux repositories.
  • I failed to reproduce this on macOS using the emacs Cask.
  • Replacing sleep-for with accept-process-output gives the same result.
  • If the snippet is run by the user after init, the sentinel runs as expected in GUI Emacs.
  • This issue arose while debugging use of async-wait from the async package during init.
6
  • 1
    I put the code in the end of my init.el then restart my Emacs (Emacs Mac Port), it does not hang forever and after Emacs finishes startup, my/test-flag is t. Commented Aug 31, 2020 at 2:24
  • 1
    I see the same result as @xuchunyang with GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars) of 2020-08-12, on Ubuntu 18.04. Commented Aug 31, 2020 at 2:32
  • 1
    I see the same behavior as @PythonNut on emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.13, cairo version 1.16.0) of 2020-04-23 (a self-built version). I did emacs -q -l foo.el where foo.el contains just the code above. Commented Aug 31, 2020 at 4:12
  • 1
    I also tried toggling debug-on-quit and added a debugging print of (process-list) in the loop: the test process appears in that output for as long as I wait: after pressing C-g I call process-list and it returns nil. Commented Aug 31, 2020 at 4:15
  • I just failed to reproduce on macOS. Commented Aug 31, 2020 at 6:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.