From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.devel Subject: Re: "Asynchronous Requests from Emacs Dynamic Modules" Date: Sun, 1 Nov 2020 21:32:48 +0100 Message-ID: References: <86imarfldb.fsf@akirakyle.com> <867dr4omov.fsf@akirakyle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3234"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier , Emacs developers To: Akira Kyle Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Nov 01 21:33:48 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 1kZK2u-0000k2-1R for ged-emacs-devel@m.gmane-mx.org; Sun, 01 Nov 2020 21:33:48 +0100 Original-Received: from localhost ([::1]:49228 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZK2s-0002Mh-UV for ged-emacs-devel@m.gmane-mx.org; Sun, 01 Nov 2020 15:33:46 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55016) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZK2B-0001r3-St for emacs-devel@gnu.org; Sun, 01 Nov 2020 15:33:03 -0500 Original-Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]:37503) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kZK29-0001zr-20 for emacs-devel@gnu.org; Sun, 01 Nov 2020 15:33:03 -0500 Original-Received: by mail-ot1-x333.google.com with SMTP id l36so2735229ota.4 for ; Sun, 01 Nov 2020 12:33:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GaxAqVVqA5sy3iDi1p0zGS9SBNkqKX22n+OGk8GyBEc=; b=YjYIGhWrco7dcF3w3V54o9O1DwINhy8y5LJfX6fXQdhGJHA/utkaBPTuI6rg58HHMA 3XZGt/igpFvjHk6+EH2VONujhxoQ6gAJO6jqcmN1+mOydjHGI+B+nXeo/ZDf3sF3OEpV RuHT983zRNdif+10Wv4rlEVyeLAvZVicGXSwrn7VTQaiiFjxmyke4qe/PK9bDSa2g9qt XTaMja67cSEjTiMpx0i97JH5LCErO1QR23kliHuPvlRjByGWwo2g/N+jGJZXKCf7QF+D giRrhsSvtGOWc8/OjTUYVDFOmZD6SQbUsPCoIVgPAL0b1LoNp0AA8FPj7RAP6S+QUCFB 7JgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GaxAqVVqA5sy3iDi1p0zGS9SBNkqKX22n+OGk8GyBEc=; b=KjC+WAbdh9xOh9BEwkEdC8sY6SuL7+w77QyXlJMSuUlVHIWaaISEwlkaDRtFMJrszN mRnRustCij81MFBvzcvtQRDQ9rJkkXYViGVvvarERUPrgr+hmbTQl6AYtssAGktlF3Lk hRxdiPBxNTDkN4qjsHqq5lzbXGit3uqlIIUkEBm43nz1bgac3/9fuLD7pBXGmV0sPbWC hm5eRMT81iXHFm0zGu9aPkuK0HzwXSl1lb7MuBDrh83InMFgThUA3mbnWHmy/TB/EWi1 xnF+wzHahSDJddaiMm5W9pR6X7UYBCqPxCEhJnCjpI/EIT1kefw2joalrqLeVxz6qj8D CYYw== X-Gm-Message-State: AOAM533y1I7ZL7J9BQ+dn81/Ltil/0uDKHwhrtd6Yha+cpKO5D21yqLA a2BVlGM9Ed9krwnysiHOIA6N68mWSn0PiZCdTXI= X-Google-Smtp-Source: ABdhPJymKrR2niHQlpYmZlNZ7JpKrxOV7FJXsuR1ikhAUK6xo5iKtNjKONsCiCWKeJYs70U/QuWLEet8nYKAc2QyqOE= X-Received: by 2002:a9d:12f3:: with SMTP id g106mr9202852otg.149.1604262779647; Sun, 01 Nov 2020 12:32:59 -0800 (PST) In-Reply-To: <867dr4omov.fsf@akirakyle.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::333; envelope-from=p.stephani2@gmail.com; helo=mail-ot1-x333.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: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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:258609 Archived-At: Am So., 1. Nov. 2020 um 21:18 Uhr schrieb Akira Kyle : > > > On Sat, Oct 31, 2020 at 06:49 AM, Stefan Monnier > wrote: > > >> With Emacs 28, you can get a file descriptor to a pipe process > >> and > >> send arbitrary data there (from arbitrary threads). > > > > Cool, so that takes care of it. > > > >> You'd still need some small protocol (e.g. JSON) to > >> encode/decode > >> requests, but with that you can send arbitrary requests > >> back asynchronously. > > > > I don't think you need a complex protocol: just stash somewhere > > (inside > > the module data structures) the data you need for the async > > request, > > then send a dummy byte to the pipe. On the Lisp side, just > > install > > a process-filter which calls back the module to "run any pending > > async > > requests". > > Thanks Philipp for pointing this out! I'm glad this was already > thought of and added so the SIGUSR1 hack isn't necessary going > forward. For future reference, the module function is > `open_channel`. I actually implemented open_channel after reading that very blogpost and thinking "there has to be a better way" :-) Note that even without that there are a few other options, e.g. starting a Unix domain socket server in Emacs and then connecting to it from the module. These are essentially equivalent in that they queue some form of event (process input) that can be processed asynchronously on the Emacs side.