From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Augusto Stoffel Newsgroups: gmane.emacs.bugs,gmane.emacs.devel Subject: bug#49822: master e32c7d2: Change Python eval to send directly instead of using temporary files Date: Tue, 07 Sep 2021 19:37:41 +0200 Message-ID: <875yvcmgm2.fsf@gmail.com> References: <20210903122828.16890.65271@vcs0.savannah.gnu.org> <20210903122829.EAAC220B71@vcs0.savannah.gnu.org> <87r1e4eklw.fsf@gmail.com> <87v93fnfmm.fsf@igel.home> <87lf4aooge.fsf@gmail.com> <878s0a409g.fsf@gmx.de> <87ilzef65i.fsf@igel.home> <878s0aeyna.fsf@gmx.de> <87r1e1ex7z.fsf@igel.home> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3934"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Andy Moreton , emacs-devel@gnu.org, Andreas Schwab , Stefan Monnier , 49822@debbugs.gnu.org, Michael Albinus , Lars Ingebrigtsen To: "Barton, Mark" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Sep 07 19:39:04 2021 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 1mNf3o-0000mS-8j for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 07 Sep 2021 19:39:04 +0200 Original-Received: from localhost ([::1]:35766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mNf3j-0000tV-Ku for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 07 Sep 2021 13:39:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mNf2p-0000qD-8D for bug-gnu-emacs@gnu.org; Tue, 07 Sep 2021 13:38:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46026) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mNf2o-0007S0-UO for bug-gnu-emacs@gnu.org; Tue, 07 Sep 2021 13:38:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mNf2o-0002Pn-RD for bug-gnu-emacs@gnu.org; Tue, 07 Sep 2021 13:38:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Augusto Stoffel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 07 Sep 2021 17:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49822 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 49822-submit@debbugs.gnu.org id=B49822.16310362729248 (code B ref 49822); Tue, 07 Sep 2021 17:38:02 +0000 Original-Received: (at 49822) by debbugs.gnu.org; 7 Sep 2021 17:37:52 +0000 Original-Received: from localhost ([127.0.0.1]:57570 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mNf2e-0002P1-Eh for submit@debbugs.gnu.org; Tue, 07 Sep 2021 13:37:52 -0400 Original-Received: from mail-wr1-f49.google.com ([209.85.221.49]:46814) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mNf2b-0002Oi-MN for 49822@debbugs.gnu.org; Tue, 07 Sep 2021 13:37:50 -0400 Original-Received: by mail-wr1-f49.google.com with SMTP id x6so15587910wrv.13 for <49822@debbugs.gnu.org>; Tue, 07 Sep 2021 10:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=K/FdNijzDKYaqBU/E5N2f74enNre7wppLpqwcmvuE6g=; b=ElrTNOLajdMbEHqcwsuzo08s5FV61dMd9SfkL26y4DpwyIunpQDAxIo3lXVnDhvhUR h3GjxPSWh5c5P/pVx/0MD6mxIbeRv6m34vcn9Lpp8WRCO/uq91YYNSS3a44f+g0uGy2K 5scBHX97CjZOB2pDcXHnNhiiv3qEWgTVx3EgGOHHvizcO8o5Kt+E4T8+OndjEYbqz3gW pkj/3V93XMpnOiMqJpjfnYuAcK/j8TTVo7YyN3+IC12yDC7vfTJfrr5AnyCoxUs95gSa ZP19MUow4l7KmMUMNC9udXN7noKp3P5ENRbq0JXb16HAqN4ZC8OsUifssgQFNxeBV0WB O8lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=K/FdNijzDKYaqBU/E5N2f74enNre7wppLpqwcmvuE6g=; b=tT9eqojvM//wKw6LolyJtxtBIqqLdtKoWXg2KTOp/z7C9/qntAa/G7eaLZLLR4PEHa bGwvlAr8guLbC+cLrffTXF5u7IJxSBt8en+cJJLqy70amks6ufP8z8KbjrV2Nvxb5dn1 Cj2++bMKcTZZFrTErXDLc/+aHPy8Ja1CmvOQ1NdrmFprv/F8trDrIXo+s1+UUjUW+wmF gzVov+oof75nPQMLtLEV1SI8sA+SoUoefyFgIx3UYLxH+XUSx7B/oZ28CRHuPBh5+kPv 128gFvwgZ7iinLeKMwOjjSdBZedM9DvH6qVGYUoj0dgrXyLvasMZVK5ddGxqAABmwqEb iLbg== X-Gm-Message-State: AOAM530N7PblBOnHqqxUowNngJ+r+4ymVNLGeQJ80OrC/uEK0abIxoAA MN3mJljctgeQEBV49LgPNL8= X-Google-Smtp-Source: ABdhPJyTf3uMJiJqMzLmXPeIA2UYxIVAeNaN2nclS2WL4mjkMlnifOmElRo96eKk7kYQoR/2tDz7GQ== X-Received: by 2002:a5d:4643:: with SMTP id j3mr20292031wrs.138.1631036263646; Tue, 07 Sep 2021 10:37:43 -0700 (PDT) Original-Received: from ars3 ([2a02:8109:8ac0:56d0::b1d]) by smtp.gmail.com with ESMTPSA id a6sm3139561wmb.7.2021.09.07.10.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 10:37:42 -0700 (PDT) In-Reply-To: <87r1e1ex7z.fsf@igel.home> (Andreas Schwab's message of "Mon, 06 Sep 2021 13:53:52 +0200") 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" Xref: news.gmane.io gmane.emacs.bugs:213718 gmane.emacs.devel:274273 Archived-At: --=-=-= Content-Type: text/plain On Mon, 6 Sep 2021 at 13:53, Andreas Schwab wrote: > On Sep 06 2021, Michael Albinus wrote: > >> Andreas Schwab writes: >> >>>>> Okay, so is the TTY line length limit of the OS available in Lisp >>>>> somewhere? Otherwise, can we at least trust that 1024 is the universal >>>>> lower bound? >>>> >>>> On systems with a POSIX shell: >>>> >>>> (let ((default-directory "/")) >>>> (read (shell-command-to-string "getconf LINE_MAX"))) >>> >>> LINE_MAX has nothing to do with the tty line discipline. >> >> I'll never learn it :-( >> >> We've discussed this issue some years ago already. IIRC, the outcome was >> to use "getconf PIPE_BUF /" instead. > > Neither has PIPE_BUF. > > Andreas. Okay then. Since there seem to be no better alternatives, I have attached a new patch reducing the limit to a hard-coded 1024 bytes. If some day someone adds a variable specifying a more precise limit, then we can change this. I have also rearranged things a bit so that the setup code is sent to the inferior process just once, rather than of on every call to `python-shell-send-string'. This way, the smaller line length limit doesn't increase too much the use of temp files, which, as I mentioned, is slow over ssh. It would be great if someone with access to a BSD-like OS could test this. I can only test locally on Linux and over ssh between Linux machines. PS: I have some more suggestions around the Python shell. Is the ideal workflow to keep creating bugs with a small patch to each improvement, or do you prefer to review a larger collection of changes bundled together? --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Reduce-limit-of-line-length-sent-to-the-Python-infer.patch >From 05947ad82219af3f4bcb228f076995f181a7255d Mon Sep 17 00:00:00 2001 From: Augusto Stoffel Date: Mon, 6 Sep 2021 23:34:48 +0200 Subject: [PATCH] Reduce limit of line length sent to the Python inferior * lisp/progmodes/python.el (python-shell-comint-watch-for-first-prompt-output-filter): Send setup code to the inferior process only once and at this stage. (python-shell-send-string-no-output): Revert changes of e32c7d2a8d (python-shell-send-string): Assume a smaller TTY line length limit, as required by some OSes. (python-shell-send-file): Ditto. --- lisp/progmodes/python.el | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index d8ec032402..347c3ffe00 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -2826,6 +2826,15 @@ python-shell-comint-watch-for-first-prompt-output-filter (setq python-shell--first-prompt-received-output-buffer nil) (setq-local python-shell--first-prompt-received t) (setq python-shell--first-prompt-received-output-buffer nil) + (cl-letf (((symbol-function 'python-shell-send-string) + (lambda (string process) + (comint-send-string + process + (format "exec(%s)\n" (python-shell--encode-string string)))))) + ;; Bootstrap: the normal definition of `python-shell-send-string' + ;; depends on the Python code sent here. + (python-shell-send-string-no-output python-shell-eval-setup-code) + (python-shell-send-string-no-output python-shell-eval-file-setup-code)) (with-current-buffer (current-buffer) (let ((inhibit-quit nil)) (run-hooks 'python-shell-first-prompt-hook)))))) @@ -3128,12 +3137,11 @@ python-shell-send-string (interactive (list (read-string "Python command: ") nil t)) (let ((process (or process (python-shell-get-process-or-error msg))) - (code (format "exec(%s);__PYTHON_EL_eval(%s, %s)\n" - (python-shell--encode-string python-shell-eval-setup-code) + (code (format "__PYTHON_EL_eval(%s, %s)\n" (python-shell--encode-string string) (python-shell--encode-string (or (buffer-file-name) ""))))) - (if (<= (string-bytes code) 4096) + (if (<= (string-bytes code) 1024) (comint-send-string process code) (let* ((temp-file-name (with-current-buffer (process-buffer process) (python-shell--save-temp-file string))) @@ -3180,8 +3188,7 @@ python-shell-send-string-no-output (inhibit-quit t)) (or (with-local-quit - (comint-send-string - process (format "exec(%s)\n" (python-shell--encode-string string))) + (python-shell-send-string string process) (while python-shell-output-filter-in-progress ;; `python-shell-output-filter' takes care of setting ;; `python-shell-output-filter-in-progress' to NIL after it @@ -3419,9 +3426,7 @@ python-shell-send-file (comint-send-string process (format - "exec(%s);exec(%s);__PYTHON_EL_eval_file(%s, %s, %s, %s)\n" - (python-shell--encode-string python-shell-eval-setup-code) - (python-shell--encode-string python-shell-eval-file-setup-code) + "__PYTHON_EL_eval_file(%s, %s, %s, %s)\n" (python-shell--encode-string file-name) (python-shell--encode-string (or temp-file-name "")) (python-shell--encode-string (symbol-name encoding)) -- 2.31.1 --=-=-=--