From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#63078: 26.1; Sentinels are sometimes unexpectedly only invoked in script mode Date: Wed, 26 Apr 2023 09:22:02 +0300 Message-ID: <837ctzuprp.fsf@gnu.org> References: <87wn1zpn8n.fsf@metalevel.at> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30039"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 63078@debbugs.gnu.org To: Markus Triska Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 26 08:22:40 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 1prYY4-0007dM-0t for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 26 Apr 2023 08:22:40 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYXc-0007c4-4f; Wed, 26 Apr 2023 02:22:12 -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 1prYXT-0007ar-9C for bug-gnu-emacs@gnu.org; Wed, 26 Apr 2023 02:22:07 -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 1prYXT-0007DX-0h for bug-gnu-emacs@gnu.org; Wed, 26 Apr 2023 02:22:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1prYXS-0002c5-D2 for bug-gnu-emacs@gnu.org; Wed, 26 Apr 2023 02:22:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 26 Apr 2023 06:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63078 X-GNU-PR-Package: emacs Original-Received: via spool by 63078-submit@debbugs.gnu.org id=B63078.168249010610020 (code B ref 63078); Wed, 26 Apr 2023 06:22:02 +0000 Original-Received: (at 63078) by debbugs.gnu.org; 26 Apr 2023 06:21:46 +0000 Original-Received: from localhost ([127.0.0.1]:54107 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1prYXB-0002bX-Nr for submit@debbugs.gnu.org; Wed, 26 Apr 2023 02:21:46 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:33662) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1prYX8-0002bF-UK for 63078@debbugs.gnu.org; Wed, 26 Apr 2023 02:21:45 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prYX2-0007Ac-JU; Wed, 26 Apr 2023 02:21:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=6hZ6rM9tR6QhvIwpT1wioq9741kt6sYMKUDOht2KF5A=; b=bKtlEgs3Co3Y 0w1N3+asCKAfVTRCeF+KvLQ3JgjViUv8FYJDLYUUFvz7gWTZeUKO3B3+Yet31zut7WsOG2NE2lgaO GOqQFvk8ccH1kxSML2rQA233jhsO0GoaFjp/wv6V7a5iqQHjkAfgShS8EdabvFoxABusyc8TtBHEB PjlNFWiwUqc078g90WqlYOVaA7N+9nC4Gc6we7yBnJ8yUCLcpMXAHbJOAD4P9iePgXYXCsc0Va4Pq bgUVrVzOKKLZEQs8Dcofazg8olQU2G0m/SQskkn8aKogqbIJGqIRwnahgRjYF27+/I6LhUhEu8vio OwrB1KnP2UbKCR/1c4zn4A==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prYWz-0001DE-D4; Wed, 26 Apr 2023 02:21:34 -0400 In-Reply-To: <87wn1zpn8n.fsf@metalevel.at> (message from Markus Triska on Wed, 26 Apr 2023 01:15:36 +0200) 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:260648 Archived-At: > From: Markus Triska > Date: Wed, 26 Apr 2023 01:15:36 +0200 > > 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. I cannot reproduce the problem with Emacs 28.2: I get "process said: hello" in the echo-area, as expected. Did you try with the -nw command-line switch, and if you do, does it change anything? It could be some timing problem: you start a program that exits almost immediately, so there could be some race condition between the program and your code.