jwiegley/emacs-async

async-start result mixes standard output with return value out of order on Emacs 27.1 for Windows

piyo opened this issue · 2 comments

piyo commented

version

async package from melpa version "async-20200809.501"

description

On Emacs 27.1 for Windows, if the child process uses the message function, the arguments are inserted into the final result after the value to be passed back to the parent. The expected behavior is the arguments are not inserted after the value to be passed back to the parent.

repro 1

This code reproduces the problem:

(defvar scratch-1 nil)
(progn
  (setq async-debug t)
  (setq scratch-1 nil)
  (async-start
   `(lambda ()
      (message "yes")
      1)
   (lambda (result)
     (setq scratch-1 result))
   ))
;; result eventually stored in this global variable
scratch-1

On "GNU Emacs 27.1 (build 1, x86_64-w64-mingw32) of 2020-08-22",
scratch-1 is '1yes and (type-of scratch-1) is 'symbol. (bad result)
Also the buffer *emacs* contains:

Lisp expression: 1yes\n

On "GNU Emacs 26.3 (build 1, x86_64-w64-mingw32) of 2019-12-31"
scratch-1 is 1 and (type of scratch-1) is 'integer. (good result)
Also the buffer *emacs* contains:

Lisp expression: yes\n
1

repro 2

Another example: This code reproduces the problem:

(defvar scratch-1 nil)
(progn
  (setq async-debug t)
  (setq scratch-1 nil)
  (async-start
   `(lambda ()
      (prin1 "omg")
      (message "hai")
      (message "yes")
      1)
   (lambda (result)
     (setq scratch-1 result))
   ))
;; result eventually stored in this global variable
scratch-1

On "GNU Emacs 27.1 (build 1, x86_64-w64-mingw32) of 2020-08-22",
scratch-1 is 'yes and (type-of scratch-1) is 'symbol. (bad result)
Also the buffer *emacs* contains:

Lisp expression: "omg"1\n
hai\n
yes\n

On "GNU Emacs 26.3 (build 1, x86_64-w64-mingw32) of 2019-12-31"
scratch-1 is 1 and (type of scratch-1) is 'integer. (good result)
Also the buffer *emacs* contains:

Lisp expression: \n
hai\n
yes\n
"omg"1

repercussions

Currently this behavior breaks the paradox package when using async mode (paradox--menu-execute-1) and some of my non-published code.

workaround

One temporary workaround would be to silence the message function in the child, at the user provided start-func:

(async-start
   `(lambda ()
      (cl-letf (((symbol-function #'message) (symbol-function #'ignore)))
        (let ((child-var1 ...))
          (do-something)
          return-val-for-parent)))
   callback-in-parent)

This presumably breaks async-debug.

solution

Unknown.

piyo commented

I forgot to mention the following:
This cannot be reproduced on Emacs 27.1 on Debian.

On Darwin using Emacs 27.1, example 1 is even more broken, erroring out with: “error in process sentinel: End of file during parsing”. I think this is because the Emacs executable (from emacsforosx.com) uses ‘message to output all its loading activity at startup.