From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 8BjRDFzFCmN4LwEAbAwnHQ (envelope-from ) for ; Sun, 28 Aug 2022 03:31:08 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id KDEDDVzFCmOOEQEA9RJhRA (envelope-from ) for ; Sun, 28 Aug 2022 03:31:08 +0200 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 B8DAD3266B for ; Sun, 28 Aug 2022 03:31:07 +0200 (CEST) Received: from localhost ([::1]:53064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oS78k-0003LX-TY for larch@yhetil.org; Sat, 27 Aug 2022 21:31:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oS77p-0003JE-Lo for emacs-orgmode@gnu.org; Sat, 27 Aug 2022 21:30:11 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:39366) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oS77i-000570-82 for emacs-orgmode@gnu.org; Sat, 27 Aug 2022 21:30:07 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oS77h-0003SE-TD for emacs-orgmode@gnu.org; Sat, 27 Aug 2022 21:30:01 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#50514: 28.0.50; org inline call to python src block req C-g to break Resent-From: Ihor Radchenko Original-Sender: "Debbugs-submit" Resent-CC: emacs-orgmode@gnu.org Resent-Date: Sun, 28 Aug 2022 01:30:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50514 X-GNU-PR-Package: org-mode X-GNU-PR-Keywords: To: "Barton, Mark" Cc: "50514@debbugs.gnu.org" <50514@debbugs.gnu.org>, Mark Barton , Lars Ingebrigtsen , Augusto Stoffel Received: via spool by 50514-submit@debbugs.gnu.org id=B50514.166165017213221 (code B ref 50514); Sun, 28 Aug 2022 01:30:01 +0000 Received: (at 50514) by debbugs.gnu.org; 28 Aug 2022 01:29:32 +0000 Received: from localhost ([127.0.0.1]:57348 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oS77D-0003RB-MB for submit@debbugs.gnu.org; Sat, 27 Aug 2022 21:29:32 -0400 Received: from mail-pj1-f50.google.com ([209.85.216.50]:54052) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oS779-0003Qt-2R for 50514@debbugs.gnu.org; Sat, 27 Aug 2022 21:29:30 -0400 Received: by mail-pj1-f50.google.com with SMTP id q3so1631618pjg.3 for <50514@debbugs.gnu.org>; Sat, 27 Aug 2022 18:29:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc; bh=bXB9zsK+zqHXZTyOQ2Mqi+bfoF4Uc+qrObxdtMRkWhk=; b=fvGW9nQiwUsR66sxn6E8BtO+H1GfOTwdv0iGerpoMNZmsFrP4OuPKgWQb4RleEmlBE X2b42vPZymP/vukxQnV47lDxDvXjAY21NkChEf+Yu2gvHsZI5G7u36P7cHfkgr1MqgjK 6yyUm1Fc1vjTaIawegNeJttUhVrW/LStxOu50UlXdv3tqEWBmnVt1VuH/toRkLlHP7YZ c+Osv+NvG+Y14/VDaH8MoS3rAGPDwrAWt66/l/+Pv7ItxclH8xvZXw/jrlfJCJZ0+0oI 9RmUIafu3uCSacY5ntEtYKVnKxZ34hcSd2/tTw6HRSsrEeTDgJABs0GXSnEYGPkPToqY uWdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc; bh=bXB9zsK+zqHXZTyOQ2Mqi+bfoF4Uc+qrObxdtMRkWhk=; b=ihVXZVzrFrvPZPhNAKJCXVvTJHWvhPJxUwDRIXKopNCjlhVXBmpX7Qvx96JDzAwTzQ qF2ANzRppSRVolM8sJ24q+Fd1QudiaSsh2Umh3/4Ox+7SAy9/j3+JC5COtJYlbY/ehDp Trk9N6qNfqzsQCsnxferSYtBYJxViPRNEblxHD5d9+UFfLBEBFuN5e6Mw6FVQB4LhPjB UnEh1jlbKzAmCrUeOKB2ctZtR+MaxGJWsdTiEOD1jCLCXKhE4h2HhY7FqUWuo96YgTyN OUpOyMBkbUyjAgrpVQEsKQOHpBleIUHbuhFDMMak4npgoGfa9YCLm4w3HiIHWRHPoqJD /Qfw== X-Gm-Message-State: ACgBeo3Pzbh6lVAdlM5PCCXccca/DW/N4mr77dFp4zDjiIuTpSS2FLIK kVx/xVovN08isT2WgR4VkN8= X-Google-Smtp-Source: AA6agR7PohiTOm9I09ah5GOL/7DsKk3xz17MklpRJAiFsABdju5Yp1prnkyt3n1ey5GvAFNvBKxn4g== X-Received: by 2002:a17:902:a705:b0:172:ecca:8d2d with SMTP id w5-20020a170902a70500b00172ecca8d2dmr10380389plq.27.1661650161233; Sat, 27 Aug 2022 18:29:21 -0700 (PDT) Received: from localhost ([2409:8a70:2b3:c8a0:8ec6:81ff:fe70:339d]) by smtp.gmail.com with ESMTPSA id k13-20020a170902ce0d00b00174a5e1afe9sm179355plg.114.2022.08.27.18.29.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Aug 2022 18:29:20 -0700 (PDT) From: Ihor Radchenko In-Reply-To: <56BAC174-35F5-4ED6-8923-729B2DE20490@disney.com> References: <9CADADD8-72C0-4951-9950-AC7149B339F4@gmail.com> <56BAC174-35F5-4ED6-8923-729B2DE20490@disney.com> Date: Sun, 28 Aug 2022 09:30:22 +0800 Message-ID: <87czclduj5.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: emacs-orgmode@gnu.org 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" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1661650267; 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:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=bXB9zsK+zqHXZTyOQ2Mqi+bfoF4Uc+qrObxdtMRkWhk=; b=fRmrtZ3RzZtjeb9JDlCFWNIW4B3iel17R9Zu1nlGbZ1DljRObVsMJvZ0rWr2cma/T3eUES ALPCSFa3FhFA78YCZl09edf/prvCKiYWu7R5aA5YDeDzazwhszjswZdhuzqfSRLkVZuJLR bh3MgnkPD7B8m4pX6m7Yhsm5hWaC6oF6jT+ll2HczVHeqlzxo20sL4ac8fA8hya3TyubmJ 55NlI2PIxAxKGVohN8C4RBVqO2F9k0M7Kdn4sP5eMKvvUFZUl4a14pvMzTHez8lnZNyTUc 5QTFzkqK3VhwMlG/iX9Mefi7FL7Io7IEBOyoVR8Dfdkl7mtoEMEaJTG5JjMjBA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1661650267; a=rsa-sha256; cv=none; b=bK3VdVx83pYvmEJhJv/vfEgAkDGk/7bJ04nWWAZv2gFjw9bIyN5SVakgoi0HM7QeNkFCMs 7bQAUhhh+Xe74+cjMxCHdiCJRyU9yv/cqCziIGKeBHnIsaIi7Zutm5B66u/CDlOlasrlqd 5x8YKS2FwdO3+lkcZ3q1Db3XzrSLU/mhXqhPNg9lffnGvB26cnBp8I38OVMcLoIcKhKuMo LSOTODHNQpCGacuuxaZGe4H0bNMHXU0nTFpTdSkY1XgRuw8WprrLdn5NUPaNarInGmyAfZ ZRR60t/E6GFyTFPo+aOLAr3jXXQ8YgqVtMF3e21nYd8DJALzwThMUxHTiP/gYw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=fvGW9nQi; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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" X-Migadu-Spam-Score: 7.70 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=fvGW9nQi; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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" X-Migadu-Queue-Id: B8DAD3266B X-Spam-Score: 7.70 X-Migadu-Scanner: scn0.migadu.com X-TUID: WzUJTbdDBfEk --=-=-= Content-Type: text/plain "Barton, Mark" writes: > I tried something that was suggested last September 14th by Augusto Stoffel. I had not tried it because changing the sleep from 10 to 90 was my workaround. > One thing that might work is to block until the shell is ready with something like > > (run-python) > (with-current-buffer *the-shell-buffer* > (while (not python-shell--first-prompt-received) > (accept-process-output (get-buffer-process (current-buffer))))) Thanks, but it is not a good solution. Org cannot rely on internal variables inside python.el (python-shell--first-prompt-received is an internal variable). Internal variables are a subject of change without notice. May you instead try the attached alternative patch? -- Ihor Radchenko, Org mode contributor, Learn more about Org mode at https://orgmode.org/. Support Org development at https://liberapay.com/org-mode, or support my work at https://liberapay.com/yantar92 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=v2-0001-ob-python-Fix-Emacs-bug-50514-when-Python-loads-s.patch >From 06373a64387330d5bbdcbb3417cea7c2638713df Mon Sep 17 00:00:00 2001 Message-Id: <06373a64387330d5bbdcbb3417cea7c2638713df.1661650102.git.yantar92@gmail.com> From: Ihor Radchenko Date: Sat, 27 Aug 2022 22:06:11 +0800 Subject: [PATCH v2] ob-python: Fix Emacs bug#50514 when Python loads slowly * lisp/ob-python.el (org-babel-python-initiate-session-by-key): Do not rely on 10ms delay to initialize Python. Wait until python process is initialized using `org-babel-comint-wait-for-output'. --- lisp/ob-python.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lisp/ob-python.el b/lisp/ob-python.el index 932aca08e..e50a7c2e2 100644 --- a/lisp/ob-python.el +++ b/lisp/ob-python.el @@ -197,8 +197,7 @@ (defun org-babel-python-initiate-session-by-key (&optional session) (setq py-buffer (org-babel-python-with-earmuffs session))) (let ((python-shell-buffer-name (org-babel-python-without-earmuffs py-buffer))) - (run-python cmd) - (sleep-for 0 10))) + (run-python cmd))) ((and (eq 'python-mode org-babel-python-mode) (fboundp 'py-shell)) ; python-mode.el (require 'python-mode) @@ -217,6 +216,8 @@ (defun org-babel-python-initiate-session-by-key (&optional session) (py-shell nil nil t org-babel-python-command py-buffer nil nil t nil))) (t (error "No function available for running an inferior Python"))) + ;; Wait until Python initializes. + (org-babel-comint-wait-for-output py-buffer) (setq org-babel-python-buffers (cons (cons session py-buffer) (assq-delete-all session org-babel-python-buffers))) -- 2.35.1 --=-=-=--