From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Markus Triska Newsgroups: gmane.emacs.bugs Subject: bug#63078: 26.1; Sentinels are sometimes unexpectedly only invoked in script mode Date: Wed, 26 Apr 2023 01:15:36 +0200 Message-ID: <87wn1zpn8n.fsf@metalevel.at> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26211"; mail-complaints-to="usenet@ciao.gmane.io" To: 63078@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 26 01:24:36 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1prS1S-0006Zc-A4 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 26 Apr 2023 01:24:34 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prS0y-0005q7-Ta; Tue, 25 Apr 2023 19:24:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prS0w-0005pW-Vz for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2023 19:24:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1prS0w-0001qC-He for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2023 19:24:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1prS0v-00076K-Vq for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2023 19:24:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Markus Triska Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 25 Apr 2023 23:24:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 63078 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.168246498527206 (code B ref -1); Tue, 25 Apr 2023 23:24:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 25 Apr 2023 23:23:05 +0000 Original-Received: from localhost ([127.0.0.1]:53758 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1prS01-00074k-3U for submit@debbugs.gnu.org; Tue, 25 Apr 2023 19:23:05 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:49220) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1prRzw-000747-Kx for submit@debbugs.gnu.org; Tue, 25 Apr 2023 19:23:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prRzw-0005hJ-8A for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2023 19:23:00 -0400 Original-Received: from [78.47.144.35] (helo=metalevel.at) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prRzr-0001dl-7h for bug-gnu-emacs@gnu.org; Tue, 25 Apr 2023 19:22:59 -0400 Original-Received: from mt-Lenovo-ideapad-120S-11IAP (localhost [127.0.0.1]) by metalevel.at (Postfix) with ESMTP id AA5E59C73F for ; Wed, 26 Apr 2023 01:15:47 +0200 (CEST) Original-Received: by mt-Lenovo-ideapad-120S-11IAP (Postfix, from userid 1000) id DD542140046; Wed, 26 Apr 2023 01:15:36 +0200 (CEST) X-Host-Lookup-Failed: Reverse DNS lookup failed for 78.47.144.35 (failed) Received-SPF: none client-ip=78.47.144.35; envelope-from=triska@metalevel.at; helo=metalevel.at X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:260641 Archived-At: Dear all, to reproduce this issue, please save the following C code in proc.c: #include #include int main() { printf("hello"); exit(0); } and compile it, yielding the program file "./proc": $ gcc proc.c -o proc Further, please store the following Elisp definitions in proc.el, in the same directory as the above program: (add-to-list 'exec-path ".") (defvar p-stopped nil) (defun my-sentinel (proc str) (when (string-match "^\\(?:finished\n\\|exited abnormally\\|killed\n\\)" str) (setq p-stopped t))) (defun wait-for-process-end (proc) (while (not p-stopped) (message "process status is: %s" (process-status proc)) (accept-process-output proc 0.1 nil t))) (defun f () (with-temp-buffer (let ((proc (start-process "p" (current-buffer) "proc"))) (setq p-stopped nil) (set-process-sentinel proc 'my-sentinel) (wait-for-process-end proc)) (message "process said: %s" (buffer-string)))) The following invocation and result shows a case where the program behaves exactly as intended: It waits for the process sentinel to signal that no more output can arrive from the process, and shows the output it got while the process was producing output: $ emacs -Q --script proc.el --eval "(f)" process status is: exit process said: hello In contrast, the following invocation produces, in the echo area, the message "process status is: exit", and Emacs hangs unexpectedly: $ emacs -Q -l proc.el --eval "(f)" The behaviour I expect in this case is analogous to the other invocation: I do expect the message we see, followed by the message "process said: hello", as in the case above. However, this second message only appears if I manually interrupt Emacs with C-g. Regarding the background of this use case: The goal of one of my Emacs scripts is to reliably obtain *all* output from a process, until the process ends (which it always does), and then end the script. A flawed attempt to do this is to check the state of the process (via process-status), and end the script when the the state is no longer 'run. However, process output can (and sometimes does) still arrive even after the state is no longer equal to 'run. Apparently only the sentinel can reliably detect that no more process output can follow. Is there a way to make Emacs invoke the sentinel in the example above? Thank you a lot! Markus In GNU Emacs 26.1 (build 3, x86_64-pc-linux-gnu, X toolkit, Xaw scroll bars) of 2019-04-09 built on mt-laptop Windowing system distributor 'The X.Org Foundation', version 11.0.12201003 System Description: Ubuntu 22.10 Configured using: 'configure --with-tiff=no' Configured features: XPM JPEG GIF PNG SOUND GSETTINGS NOTIFY GNUTLS LIBXML2 FREETYPE XFT ZLIB TOOLKIT_SCROLL_BARS LUCID X11 THREADS Important settings: value of $LC_MONETARY: en_GB.UTF-8 value of $LC_NUMERIC: en_GB.UTF-8 value of $LC_TIME: en_GB.UTF-8 value of $LANG: en_US.UTF-8 value of $XMODIFIERS: @im=ibus locale-coding-system: utf-8-unix