From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Paul Pogonyshev Newsgroups: gmane.emacs.devel Subject: graceful shutdown of non-interactive Elisp program Date: Sat, 13 Jun 2020 23:42:51 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000000123f605a7fe1420" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="3666"; mail-complaints-to="usenet@ciao.gmane.io" To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jun 13 23:44:10 2020 Return-path: Envelope-to: ged-emacs-devel@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 1jkDwf-0000sJ-G8 for ged-emacs-devel@m.gmane-mx.org; Sat, 13 Jun 2020 23:44:09 +0200 Original-Received: from localhost ([::1]:53836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jkDwe-0004Of-Ij for ged-emacs-devel@m.gmane-mx.org; Sat, 13 Jun 2020 17:44:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58730) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jkDvj-0003kR-Sd for emacs-devel@gnu.org; Sat, 13 Jun 2020 17:43:11 -0400 Original-Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:39634) by eggs.gnu.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jkDvi-0002uE-3I for emacs-devel@gnu.org; Sat, 13 Jun 2020 17:43:11 -0400 Original-Received: by mail-wr1-x42f.google.com with SMTP id t18so13419568wru.6 for ; Sat, 13 Jun 2020 14:43:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=FD/Jb78yUdXPkT5ia0lXEK+VRIQVdyt43LtAd42/9A8=; b=VMWZ+2BsueuG9BIThSlAqaP2qdjI+jS7V/4ZmzkxxceGytjzFhBNZq4WdRy7Ehkwp5 hE8K0w4puCUL/M3aZtoMhhWYJ6JXt1awe52vHpvRouh0jvSx0v+ufg+KV3vU3cwZSVdC eosPcFNV/Keh0F2xW/TzEPsev7+lFwRZYG28GWDEcdtZh+VZzHGztv8DUzSzHblgA18S d/NyxuYDjK4tq4D3g62vhv0+CIk0g4Fx+aysF1/N5iMkjrQwEjpH7NTfQXP0i/+LI5il DImvTjtg/8SRoYZWUEBjcAlLxbMAJkNTZWmlPmCICl7vbb/T7X06nv/FvrEFFFNAUBvV JCyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=FD/Jb78yUdXPkT5ia0lXEK+VRIQVdyt43LtAd42/9A8=; b=X8gtllYRPLvrcXKFhCd1lZ0wtbnKar6davbGJaAb/ZU2txCFzLvYNiu2mFnQ5+mE0Q yLrUixY+MEBSgbuHiRQx28CuUJamAAHNaSMJp9eGwxzvvheKwu+a0bkEPqk/2B+QwrP+ tHx15x1NYn16lWqDGj1DxcxtdT+QcWnNeYhkew3blopyi9HVYSKBVd8qbaaHlsSi+3PR PJyKuZhI45A/LlkxVKeZCoqPS5wUxNnRmDSB1pun69DHAtiZ291dlba5y0hLht6HJ0xx TXP+pYNsaxGtmDK5KNWK7D1486/L75fy68wgQrY038mRAsg6qG/UYmZkJXstHTKh9lJn z3pQ== X-Gm-Message-State: AOAM532SjZaQxU2FhkoW7jHg7GptVCklK6vCj6n1q6K+yDvfUyeYf14U 7uS4UKAwA18iLVKBXKsttjZlGxxUAXAGYcCFY5d/yOE= X-Google-Smtp-Source: ABdhPJykA/TV8kXke6+sIgT/aplYu6poEKq91MgOYaWhOAZgZR5Opi4rpHoemcplAsHZw4AClt7dJ45Y+Mfk0EthmNk= X-Received: by 2002:adf:d851:: with SMTP id k17mr21176001wrl.30.1592084582701; Sat, 13 Jun 2020 14:43:02 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=pogonyshev@gmail.com; helo=mail-wr1-x42f.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:252212 Archived-At: --0000000000000123f605a7fe1420 Content-Type: text/plain; charset="UTF-8" Hi, I'm trying to make a Elisp program that is run in a non-interactive mode, i.e. essentially as `emacs --batch --load myfile.el'. A normal way to shutdown terminal programs is with C-c, which is expected to be "graceful" shutdown, e.g. the program still has a chance to save files etc. However, with Elisp I'm not sure how to achieve that except for constantly modifying `kill-emacs-hook', which would be a nightmare from coding perspective. Naively I would expect this print "GOING DOWN" when aborted with C-c: $ emacs --batch --eval "(unwind-protect (while t) (message \"GOING DOWN\"))" For example, Python's handler of SIGINT raises an exception within the program, which unwinds the stack as usual and, unless caught, cause program termination after cleaning up as expected (e.g. running all `finally' clauses and closing all `with' context managers). However, in Elisp, as I understand, there is no way to have a say in handling SIGINT other than adding a function to `kill-emacs-hook'. Is that correct, or am I missing something here? Paul --0000000000000123f605a7fe1420 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

I'm trying to make a Elisp program = that is run in a non-interactive mode, i.e. essentially as `emacs --batch -= -load myfile.el'. A normal way to shutdown terminal programs is with C-= c, which is expected to be "graceful" shutdown, e.g. the program = still has a chance to save files etc.

However, wit= h Elisp I'm not sure how to achieve that except for constantly modifyin= g `kill-emacs-hook', which would be a nightmare from coding perspective= .

Naively I would expect this print "GOING DO= WN" when aborted with C-c:

=C2=A0 =C2=A0 $ emacs = --batch --eval "(unwind-protect (while t) (message \"GOING DOWN\&= quot;))"

For exam= ple, Python's handler of SIGINT raises an exception within the program,= which unwinds the stack as usual and, unless caught, cause program termina= tion after cleaning up as expected (e.g. running all `finally' clauses = and closing all `with' context managers). However, in Elisp, as I under= stand, there is no way to have a say in handling SIGINT other than adding a= function to `kill-emacs-hook'.

Is that co= rrect, or am I missing something here?

Paul
<= /div> --0000000000000123f605a7fe1420--