From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id IPHEAQNuzmXUrwAAqHPOHw:P1 (envelope-from ) for ; Thu, 15 Feb 2024 21:03:15 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id IPHEAQNuzmXUrwAAqHPOHw (envelope-from ) for ; Thu, 15 Feb 2024 21:03:15 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=excalamus.com header.s=zmail header.b=OD+98RvX; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none; arc=pass ("zohomail.com:s=zohoarc:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1708027394; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=/CFmQJmKZGyUbqvpH7OV3+T+uW1dK15CdhEMTM/DDFU=; b=NzAWepTl3PqGuFnyx5mTM+DbPtzmlr0dBn5y0sbS/5Bg5OEhFIRz2xFjY787Nm7umiqErO VRyGeR3HNabrlN6g2r+5MxNmcszpQsYvc33JueTsFBRwoNykhu4utNTvP0wThyfUwdRsgB SCLzNVHN8kZ016sRpBSSo+Tuq7DgrBZ+LAmEfpkbjiCfn9KubgxtNhZQtzQkR7L85r3nFY jKzxiH3IWsn7e4m1yUm5mrFsuCpu8j5eiQ94e4zHTnVNTN2zf6Y9OffEG9cz5RE5ufawpO Y5C7Ensnp6Ns78VC9KmCULTO0S8E7I8v1Ur1/D/xcKuExi8jRPdGJ7Ar2UjV0A== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=excalamus.com header.s=zmail header.b=OD+98RvX; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none; arc=pass ("zohomail.com:s=zohoarc:i=1") ARC-Seal: i=2; s=key1; d=yhetil.org; t=1708027394; a=rsa-sha256; cv=pass; b=Qb0r81imx5U8WC0V0EZY2uVjC07Y25kF/mj6x01W32la3+iHXVSZeehz2DjlhHzBe31g8T XkpSz33unTfIDwmQQSWwjYJBoOf4ZwqN2h3zYZTlQ3cbmo9AAoyk9Z4VQQySVzcmI0w522 j8Ex9i0utvnAsxPRAln65U0YoUmX+6Z9ZcsCUBuqJRswO140AyzGwdi5iYlH7wKOxTWRp+ JFXqXl/s7M48qArLo00ATDHG853olhUxilDDAXJW3IvHIaj2CThnm/11m1XIDD9dfRx6Gw PxIiddGuSI3VEMLtBnYjtb9PNUldmnmOKMKHsAYAAjwlfGKaINCL0k4oBN26Iw== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 9E3D9698D5 for ; Thu, 15 Feb 2024 21:03:14 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rahvy-0001up-AN; Thu, 15 Feb 2024 15:02:14 -0500 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 1rahvx-0001uY-3C for emacs-orgmode@gnu.org; Thu, 15 Feb 2024 15:02:13 -0500 Received: from sender4-pp-f112.zoho.com ([136.143.188.112]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rahvu-0003Fd-En for emacs-orgmode@gnu.org; Thu, 15 Feb 2024 15:02:12 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1708027326; cv=none; d=zohomail.com; s=zohoarc; b=Eiu1BFB2rvqCGsTZsQqM51uAWk64c325IGVoC/6khVLFcFWC4gmEPtOfdlcn3+pPdf1J+rCrdfJPvG3GUXZgAOMpAuYdRXKSpehVif+9q7zyv1D1cMr0ATsSauUvuiXn8wP0z8vmYLiF03VMMS+qPaUF6C7E+jqgIBOChCl1xUE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708027326; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=/CFmQJmKZGyUbqvpH7OV3+T+uW1dK15CdhEMTM/DDFU=; b=E8jQTNrPBK78DB5HyJ1CuttqLSCEHp9JljugpL90Kf7hCi1oYBnu3RwoaAwkpJtGWhMSASPJqvSyt3XC4+2LWlVoySFWWPLVMrXPrg96MbZIn1TGEKmS6LIlosxyblTHvVD1UETXbJ1weGmYhLBS2YVwmCBqdVVfmNk8UJwDniI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=excalamus.com; spf=pass smtp.mailfrom=matt@excalamus.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1708027326; s=zmail; d=excalamus.com; i=matt@excalamus.com; h=Date:Date:From:From:To:To:Cc:Cc:Message-ID:In-Reply-To:References:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=/CFmQJmKZGyUbqvpH7OV3+T+uW1dK15CdhEMTM/DDFU=; b=OD+98RvX1cr6vA7UDscJSrSZPzygQMyeNussKI8dcpMJJTcuNcFtJ0E+4ElF1NBy aO3EvXeZX1jMQU2i8AtHhpZCecJTJntXHzosrVErouUA93xO2n77KEaJbv205M/dVIC pKYWdunAmQzgrqT29CC6jVc19yxhd/VS2uWPF5Lw= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1708027325238890.8316073492912; Thu, 15 Feb 2024 12:02:05 -0800 (PST) Date: Thu, 15 Feb 2024 21:02:05 +0100 From: Matt To: "Bruno Barbier" Cc: "Ihor Radchenko" , "Jack Kamm" , "emacs-orgmode" Message-ID: <18dae5cab1d.bf1c7563863897.4896289306902277373@excalamus.com> In-Reply-To: <65c2875f.050a0220.caf6d.8291@mx.google.com> References: <87o7d0mm54.fsf@localhost> <65bbb108.050a0220.b60fd.6790@mx.google.com> <87jznm8hcu.fsf@gmail.com> <875xz42rp9.fsf@localhost> <874jen8zec.fsf@gmail.com> <87o7cv9e80.fsf@localhost> <65c2875f.050a0220.caf6d.8291@mx.google.com> Subject: Asynchronous blocks for everything (was Re: [BUG] Unexpected result when evaluating python src block asynchronously [9.7-pre (release_9.6.17-1131-gc9ed03.dirty @ /home/yantar92/.emacs.d/straight/build/org/)]) MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail Received-SPF: pass client-ip=136.143.188.112; envelope-from=matt@excalamus.com; helo=sender4-pp-f112.zoho.com 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -3.24 X-Spam-Score: -3.24 X-Migadu-Queue-Id: 9E3D9698D5 X-TUID: b4zuPI5dqnrs If I followed correctly, the topic switched to discussing async generally w= ithin Babel. I've started a new thread accordingly. ---- On Tue, 06 Feb 2024 20:24:13 +0100 Bruno Barbier > FWIW, I've been trying to use asynchronous blocks for everything, not on= ly the source blocks that are based on the comint mode. I've been trying to figure out how to make everything async by default. I'= m super interested to see what you've come up with. > I think it would be good if ob-core itself could provide an asynchronous= API. Fortunately or unfortunately, depending on how you look at it, Babel alread= y does. The challenge is that the Org Babel API has grown piecemeal over 14 years. = It's been written by several authors with limited time and knowledge. The= result, while powerful and useful, is a bit of a hodgepodge. A prime exam= ple is that the concepts of "persistence" and "synchronicity" are conflated= . "Session" is often used to mean "asynchronous" even though the two ideas= are orthogonal. Emacs provides primitives that could make non-session blo= cks asynchronous. It's historical accident that blocks aren't async by def= ault. For me, the issue is that the Babel API needs some high level perspective i= n order to make it consistent. I see the following terms as guides. If we= can separate these concepts within the API, then Babel to *feel* like an A= PI: - "Session" means a shell environment is "persistent." Each call is execut= ed in the same environment. State exists between calls. - "Non-session" means a shell environment is "temporary." Each call is exe= cuted in an independent environment. State does not exist between calls. - "Synchronous" means that execution prevents the user from editing the doc= ument while results are obtained. - "Asynchronous" means that execution does not prevent the user from editin= g the document while results are obtained. > I've modified my Org so that it does have such an API. This is work in = progress; let me describe it. > > I've modified ob-core itself to allow asynchronicity. In the asynchroso= us case, instead of calling: > > (org-babel-execute:LANG body params) > > I'm calling: > > (org-babel-schedule:LANG body params handle-result) > > where `org-babel-schedule:LANG' is in charge of calling `handle-result' = with the result (or the error) when it is known; `handle-result' takes care= to call `org-babel-insert-result' at the correct place (and `org-babel-ins= ert-result' is only called with a real result). > > While the execution is pending, I'm using the same technique that Org is= using when a source block is being edited: the result is left untouched, b= ut below an overlay. The overlay is used to know where to insert the resul= t and to display the status/progress of the execution. If the file is clos= ed and the execution fails, nothing is lost, the old result is still availa= ble. The use of the overlay is a really cool idea! I hesitate to say that's a good way to convey success or failure. If a pro= cess failed, I want to see the output which tells me why so that I can corr= ect it. Or, I might actually want the failure output. Maybe I want to lit= erally demonstrate what a code failure looks like. Maybe I want to use tha= t output in another block. For example, shell blocks have multiple output = types. A shell process may return standard output/error or a failure code.= The result of the failure may trigger something else. However, using an overlay to communicate "the process is still running" cou= ld be good. We'd need to be careful about accessibility, though, and make = sure the overlay is apparent, visually and otherwise. > If that technique looks safe enough and interesting, I can prepare a set= of patches so that we can discuss it further and, maybe, add it in Org. Please do! I'm super interested. I've put a lot of thought into how we mi= ght make Babel async by default. I'm excited to see your interest in the t= opic and look forward to seeing what you've come up with. -- Matt Trzcinski Emacs Org contributor (ob-shell) Learn more about Org mode at https://orgmode.org Support Org development at=C2=A0https://liberapay.com/org-mode