Subject: bug#78946: 30.1; accept-process-output not allowed in threads on macOS

From: Eli Zaretskii <[email-masked]>
Date: Thu, 03 Jul 2025 13:12:32 +0300

> From: John Wiegley <[email-masked]>
> Date: Wed, 2 Jul 2025 12:19:31 -0700
> Cc: [email-masked],
>  [email-masked]
> 
> If I run the attached code from the terminal using:
> 
> #+begin_src sh
> emacs -batch -Q -l accept-process-bug.el
> #+end_src
> 
> It will correctly run forever, processing output from the “yes” command (you
> can convince yourself of this by adding a debug statement inside the process
> filter, but it will be extremely noisy).
> 
> If you now attempt to evaluate this code in a graphical Emacs running on
> macOS, it will immediately stall out. Running Emacs under lldb shows that it
> is reporting the following exception continuously:

Please elaborate on "will immediately stall".  Does it mean it will
not "run forever" as in batch mode?  If so, what will it do instead?

> #+begin_example
> 2025-07-02 12:10:23.857272-0700 Emacs[34130:54192679] [General] nextEventMatchingMask should only be called from the Main Thread!

This message seems to be relevant, no?  Can some macOS expert explain
what it means, and how is that related to ns_select?

> 2025-07-02 12:10:23.857732-0700 Emacs[34130:54192679] [General] (
>       0   CoreFoundation                      0x0000000193d66ca0 __exceptionPreprocess + 176
>       1   libobjc.A.dylib                     0x000000019382ab90 objc_exception_throw + 88
>       2   AppKit                              0x00000001985baefc -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3068
>       3   AppKit                              0x0000000197c0ec64 -[NSApplication run] + 480
>       4   Emacs                               0x000000010040f400 -[EmacsApp run] + 100
>       5   Emacs                               0x000000010040d35c ns_select_1 + 1080
>       6   Emacs                               0x000000010040cefc ns_select + 72
>       7   Emacs                               0x000000010036d148 wait_reading_process_output + 4784
>       8   Emacs                               0x000000010036bdb8 Faccept_process_output + 1268
>       9   Emacs                               0x00000001002cda90 eval_sub + 2252
>       10  Emacs                               0x00000001002ce20c Fprogn + 112
>       11  Emacs                               0x00000001002ce3b8 prog_ignore + 24
>       12  Emacs                               0x00000001002d19ac Fwhile + 132
>       13  Emacs                               0x00000001002cd62c eval_sub + 1128
>       14  Emacs                               0x00000001002ce20c Fprogn + 112
>       15  Emacs                               0x00000001002d108c FletX + 876
>       16  Emacs                               0x00000001002cd62c eval_sub + 1128
>       17  Emacs                               0x00000001002ce20c Fprogn + 112
>       18  Emacs                               0x00000001002d84ec funcall_lambda + 1832
>       19  Emacs                               0x00000001002d7618 funcall_general + 288
>       20  Emacs                               0x00000001002cf438 Ffuncall + 472
>       21  Emacs                               0x00000001003c3c10 invoke_thread_function + 64
>       22  Emacs                               0x00000001002d32c4 internal_condition_case + 148
>       23  Emacs                               0x00000001003c22dc run_thread + 344
>       24  libsystem_pthread.dylib             0x0000000193c0ac0c _pthread_start + 136
>       25  libsystem_pthread.dylib             0x0000000193c05b80 thread_start + 8
> )
> #+end_example