From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Felix Dietrich Newsgroups: gmane.emacs.help Subject: Re: unwind-protect and inhibit-quit Date: Fri, 16 Jul 2021 23:30:31 +0200 Message-ID: <8735seosjs.fsf@sperrhaken.name> References: <875yxbr4lr.fsf@sperrhaken.name> <83eeby680s.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5342"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jul 16 23:31:22 2021 Return-path: Envelope-to: geh-help-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 1m4VQY-0001D1-Ot for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 16 Jul 2021 23:31:22 +0200 Original-Received: from localhost ([::1]:37882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m4VQX-0007aD-QL for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 16 Jul 2021 17:31:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m4VPu-0007Wm-7G for help-gnu-emacs@gnu.org; Fri, 16 Jul 2021 17:30:43 -0400 Original-Received: from mout.kundenserver.de ([212.227.17.24]:50757) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m4VPq-000071-RS for help-gnu-emacs@gnu.org; Fri, 16 Jul 2021 17:30:42 -0400 Original-Received: from localhost ([77.11.230.244]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MnZwp-1lNARF0weD-00je3v for ; Fri, 16 Jul 2021 23:30:36 +0200 In-Reply-To: (Stefan Monnier via Users list for the's message of "Fri, 16 Jul 2021 11:00:14 -0400") X-Provags-ID: V03:K1:4usBb0w/yriOdmCZ/18Eor356nLkK9Y+czjpNrnXQ8pUu9TISHf p8Ya4jmixN6pcm8iKXpZqHxCNLp2ou2QO9gdT2ii7yyNuhO/Nk+F9qPvKooysf3DwHtjGg3 zg2Yfnwi9gHmVn7F7WRvL4TVpD6Nyr82hyIcHJ4EYrjF+/k7+hJnto2yQ/tQ5vNDWcfrl2e bn9fCQfPy/6X/1GAALC4Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:bC5CCS3yHhE=:u1BCtrtXCUiNCvHonZ0iZC WKihiI3p57daurtG9z54Bi4FYj+UDGTBSM+VeJ++qBv3E7olQUxC83e+ShkCi/3aNibUA95vR AHDgwnlowrIwb2sOnwlLFSubcqe93qtJAnWaZGapurCqRKT5498cNSmD6bW48xHDLPIqt/57x OMW+WEqXbuUkkqkxCxGDmB4HkGNU9lbCMYXKXkkJs8PBI1S+JikghK2ODDZ1w6JYxVOQ1Zxfz +/WNhMfK3TiW0tnTOv3xDN0T1nxltpzR3h9sCDq+J7ttBAmXOE2uBf3znKpe/BadZAxqsSpIH XvHrZxIDVkkUxbT3vyBtwcZTUhktvKVeDXdcVap8cZ100YHx3WRdmvIaolzFrHfci2CPk4EMv Hxv11pFB2eCDre0DidF6EWsGzChRipB0WFYxnMimwtzZQA8bWC19VX8pnHPKLhlz4DjW6wSHk DBRHdOKGO0INbx+BiqjLq2MpCJFna1yulSaubq3BYDhH/4s5FvB4o3aIja0DRPpY0pAXjrjCB /0vNgcdNCj5hj2BgyLzN+tw95bYlS+Ir1riwK4nOsIYcAK0phEnN5fvNeEppqh0CuMDoFkpZd XHNbasVWAoxRyX0QCkx3bBp1GPmnljshaWr1Rvass833d1dpaCeB/wO8QSlkL8LVzexnXNL64 n/ICGy9A7GhbnO74k4TuR2+bUY50F3DtsIFhpDnvy3Uz/rLah0/21xoHXb1YhqYjCRcyE+tI7 BdbZaYZgYB1I9letF9NHZmx1P15gCmUy7LaPPsbkS0YzeKjvat6OtUPWLLq4ppnDLptKxxSD Received-SPF: none client-ip=212.227.17.24; envelope-from=felix.dietrich@sperrhaken.name; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:131772 Archived-At: Stefan Monnier via Users list for the GNU Emacs text editor writes: >> Now I'm curious too... Would something like this work? >> >> (let ((inhibit-quit t)) >> (setq process >> (let ((inhibit-quit nil)) >> (ftp-setup-buffer host file)))) > > No. The problem is not in the `setq` itself but in the fact that > a non-local exit from `ftp-setup-buffer` (e.g. because of `C-g`) will > cause `ftp-setup-buffer` not to return the process. But at which point is the =E2=80=98quit-flag=E2=80=99 actually handled? Wh= en unwinding the function, just before returning a value? The macro =E2=80=98with-local-quit=E2=80=99 states that the =E2=80=9Cquit-flag=E2=80= =9D =E2=80=9Cwill not be handled until the next function call=E2=80=9D[1]. Could, therefore, a careful and cooper= ative =E2=80=9Cftp-setup-buffer=E2=80=9D ensure that the process is either cleane= d-up or returned? I am thinking of something like the following: (defun ftp-setup-buffer (host file) (let (process) (condition-case nil (progn (let ((inhibit-quit t)) ;; I am assuming that =E2=80=98start-process=E2=80=99 does = not block for a ;; long time. Does it? Maybe with a defective drive? ;; How about =E2=80=98start-file-process=E2=80=99? (setq process (start-process =E2=80=A6))) ;; do more stuff process) (quit ;; I guess another quit could happen here; nest more ;; =E2=80=98condition-case=E2=80=99? It=CA=BCs =E2=80=98conditi= on-case=E2=80=99 all the way down. (and (processp process) (kill-process process)) (setq quit-flag t) ;; Propagate quit and make sure an outside handler receives it. ;; I do not have a good understanding of this. I simply copied ;; it from the =E2=80=98with-local-quit=E2=80=99 macro. (eval '(ignore nil)))))) (let (process) (unwind-protect (let ((inhibit-quit t)) (setq process (with-local-quit (ftp-setup-buffer host file))) ;; do stuff ) (and (processp process) (kill-process process)))) > We should devise a more reliable API, tho I'm not completely sure what > it should look like. Maybe > > (let ((list-of-created-processes nil)) > (unwind-protect ... > (mapc #'delete-process list-of-created-processes))) > > Where the low-level primitives which create processes add them to > `list-of-created-processes`. How do the low-level C functions to create processes handle quit? If it happens inside of them, they should be responsible for killing the process. But I am understanding that there is a step in between the creation of the process object, the return from a process creation primitive, and the assignment of the process object to a variable. > But then this gets into trouble when some unrelated code is run during > `...` (e.g. via timers or whatnot) which creates unrelated processes, > so we'd need some extra care to make sure those processes don't get > added to "the same" `list-of-created-processes`. If I am allowed to spitball here: create another function call to =E2=80=9Cclaim=E2=80=9D a process, and subject unclaimed processes to a sim= ilar clean-up routine as buffers (with =E2=80=98clean-buffer-list=E2=80=99): (let (process) (unwind-protect (progn (setq process (ftp-setup-buffer host file)) (claim-process process) ;; do stuff ) (and (processp process) (kill-process process)))) Add an optional CLAIMED parameter to process creation primitives that defaults to t in order to not disturb existing code. Naturally, I have no idea how to implement that nor the skill to figure this out. Footnotes: [1] Although there is also this information in (info "(elisp) Quitting"): =E2=80=9CEventually, =E2=80=98inhibit-quit=E2=80=99 will become =E2=80= =98nil=E2=80=99 again, such as when its binding is unwound at the end of a =E2=80=98let=E2=80=99 form. At= that time, if =E2=80=98quit-flag=E2=80=99 is still non-=E2=80=98nil=E2=80=99, the= requested quit happens immediately.=E2=80=9D --=20 Felix Dietrich