From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Manuel Giraud via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#63311: 30.0.50; [PATCH] smtpmail-send-it split Date: Fri, 12 May 2023 08:24:36 +0200 Message-ID: <87h6si5aor.fsf@ledu-giraud.fr> References: <87jzxmsyyr.fsf@ledu-giraud.fr> <83ttwqhahy.fsf@gnu.org> <874joq34bk.fsf@ledu-giraud.fr> <83o7mygevr.fsf@gnu.org> <87wn1hzv9j.fsf@ledu-giraud.fr> <871qjoe7cw.fsf@ledu-giraud.fr> <837ctf575q.fsf@gnu.org> <87ilcypot3.fsf@ledu-giraud.fr> <83pm763y3r.fsf@gnu.org> Reply-To: Manuel Giraud 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="23752"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 63311@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 12 08:25:17 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 1pxMDM-0005vX-P0 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 12 May 2023 08:25:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pxMDB-0006ij-1z; Fri, 12 May 2023 02:25:05 -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 1pxMD8-0006iV-Eq for bug-gnu-emacs@gnu.org; Fri, 12 May 2023 02:25:02 -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 1pxMD8-0003C8-5u for bug-gnu-emacs@gnu.org; Fri, 12 May 2023 02:25:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pxMD8-000771-0U for bug-gnu-emacs@gnu.org; Fri, 12 May 2023 02:25:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Manuel Giraud Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 12 May 2023 06:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63311 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 63311-submit@debbugs.gnu.org id=B63311.168387268227308 (code B ref 63311); Fri, 12 May 2023 06:25:01 +0000 Original-Received: (at 63311) by debbugs.gnu.org; 12 May 2023 06:24:42 +0000 Original-Received: from localhost ([127.0.0.1]:53819 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxMCo-00076N-0S for submit@debbugs.gnu.org; Fri, 12 May 2023 02:24:42 -0400 Original-Received: from ledu-giraud.fr ([51.159.28.247]:7010) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pxMCl-00076C-Oe for 63311@debbugs.gnu.org; Fri, 12 May 2023 02:24:41 -0400 DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=JmEWDQGI Mf/pWOL4OBtJr/YR5WdA2UxZQ875d2YPquU=; h=date:references:in-reply-to: subject:cc:to:from; d=ledu-giraud.fr; b=JJ1JWB7oB+CuRA60sP6GpKVkW4bXzQ Wd+HOoBsO2PMhHLmngwifIUCrEOdI8m8sbVXQjZ7OEFHcboqJ3gicZDQ== DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=JmEWDQGIMf/pWOL4 OBtJr/YR5WdA2UxZQ875d2YPquU=; h=date:references:in-reply-to:subject: cc:to:from; d=ledu-giraud.fr; b=ErF5di0Z+qBKajcSlJHIFOWPTxFfDuTyASX8Yd N8vRzP/RzFsojtcUMU0GkpatbWjMPDI52A2XGcHcML3T9pAKyZd2srWKzN1/JHKZ4jhsM6 FXtyU7adyoiSwKoTcr+0ccgICY9PEcmbVyhmsADk3zHiaN5DP+gTp5BRKTajjwNrQk+APb 5aKEmZZzfpsg6kUZo5qCvGnv4T/8gAuwsYauBzNwnOSdA8J+MKNChxUaFnslaSGqbnEQoL /kTM5KIVcRXDC4aV5Kxw/gJFE3HcNvqo8LRuPftKWDGYEYxTwWfD1DZVyO7MmfIoiOZjI/ Jee7D5sSjzQfsRXW/NCoBcbA== Original-Received: from computer ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id e5d4248c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 12 May 2023 08:24:37 +0200 (CEST) In-Reply-To: <83pm763y3r.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 12 May 2023 08:41:44 +0300") 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:261604 Archived-At: Eli Zaretskii writes: >> From: Manuel Giraud >> Cc: 63311@debbugs.gnu.org >> Date: Thu, 11 May 2023 22:59:20 +0200 >>=20 >> (defun my-problem () >> (interactive) >> (let ((buf (generate-new-buffer "*foo*"))) >> (with-current-buffer buf >> (insert "secret message")) >> (unwind-protect >> (make-thread #'(lambda () >> (with-current-buffer buf >> (sit-for 10) >> (message (buffer-string))))) >> (kill-buffer buf)))) >> --8<---------------cut here---------------end--------------->8--- >>=20 >> The thread won't have a chance to do its job since the buffer will >> already be dead. > > Of course. So you cannot do that, obviously. Cleanup that gets in > the way of code you run in a thread must be done after thread-join > returns, or when thread-live-p returns nil for the thread. Or use > some other synchronization method. There could be several such > threads alive at the same time, btw. > > In the unwind-protect handler of the main thread you can only do > cleanup of stuff that the thread doesn't need, or if you are sure the > thread was not started (due to some error that precludes the call to > make-thread). Thanks! So I could go with something like this: --8<---------------cut here---------------start------------->8--- (setq-local lexical-binding t) (defun eli-solution () (interactive) (let ((buf (generate-new-buffer "*foo*"))) (with-current-buffer buf (insert "secret message")) (let ((cleanup #'(lambda () (kill-buffer buf))) thread) (unwind-protect (setf thread (make-thread #'(lambda () (with-current-buffer buf (sit-for 10) (message (buffer-string)) (funcall cleanup))))) (unless (thread-live-p thread) (funcall cleanup)))))) --8<---------------cut here---------------end--------------->8--- BTW, do you know a more elisp way of defining a function than "(let ((f #'(lambda=E2=80=A6))))" form? --=20 Manuel Giraud