Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

6 May, 2024: The networking issue during the past two days has been identified and may be fixed. Will keep monitoring.


devel / comp.lang.python / on GNU EMACS's python-mode, loading entire buffer

SubjectAuthor
* on GNU EMACS's python-mode, loading entire bufferMeredith Montgomery
+* Re: on GNU EMACS's python-mode, loading entire bufferPaul Rubin
|`- Re: on GNU EMACS's python-mode, loading entire bufferMeredith Montgomery
`* Re: on GNU EMACS's python-mode, loading entire bufferMeredith Montgomery
 `* Re: on GNU EMACS's python-mode, loading entire bufferMeredith Montgomery
  `* Re: on GNU EMACS's python-mode, loading entire bufferStephen Berman
   `- Re: on GNU EMACS's python-mode, loading entire bufferMeredith Montgomery

1
on GNU EMACS's python-mode, loading entire buffer

<86y1v6zzf3.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19366&group=comp.lang.python#19366

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!M+UzZZ6ThUS76UHmDkoHCg.user.46.165.242.91.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.python
Subject: on GNU EMACS's python-mode, loading entire buffer
Date: Mon, 29 Aug 2022 15:18:24 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86y1v6zzf3.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="40559"; posting-host="M+UzZZ6ThUS76UHmDkoHCg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:zWQXZ3636xy6E4nuDp85t753CJE=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Mon, 29 Aug 2022 18:18 UTC

Perhaps this isn't the right newsgroup, but I kinda feel I will find
more GNU EMACS users running the native python-mode here than in GNU
EMACS newsgroups. Not every GNU EMACS user cares about Python.
(Right?)

A sort of a complaint is that when I used to run GNU EMACS 24.3.1, I'd
open a file.py and simply say C-c C-c and it would ask me if I wanted a
dedicated process, load a REPL load my entire buffer.

Now in 27.1, things are different. I say C-c C-c and it tells me to
start the process with C-c C-p. I mean --- is that the most polite
thing to do? I feel like it's telling me --- go send this buffer
yourself!

I also don't know how to start a dedicated process. (Sometimes I want
two REPLs. You know, you can get never get enough.)

I would bet all of this and more is available, but I don't even know
which book to read. Would you point me in the right direction?

I would also be interested in a command that restarts the REPL afresh
and reloads my buffer --- sort of like keyboard's [F5] of the IDLE.

Re: on GNU EMACS's python-mode, loading entire buffer

<87zgfmyj0f.fsf@nightsong.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19368&group=comp.lang.python#19368

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: no.em...@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.python
Subject: Re: on GNU EMACS's python-mode, loading entire buffer
Date: Mon, 29 Aug 2022 11:58:08 -0700
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <87zgfmyj0f.fsf@nightsong.com>
References: <86y1v6zzf3.fsf@levado.to>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="3b66c8f256d6db97f7ef7c12d8e2bdf4";
logging-data="1297518"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+LzQTn7Kao9gDFBey41XjS"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:xthwz2zYUxgKx4zdgcPdWCL2Xn8=
sha1:xTbjYChaxE2YszqFWeKCP1HJJgs=
 by: Paul Rubin - Mon, 29 Aug 2022 18:58 UTC

Meredith Montgomery <mmontgomery@levado.to> writes:
> Now in 27.1, things are different. I say C-c C-c and it tells me to
> start the process with C-c C-p. I mean --- is that the most polite
> thing to do? I feel like it's telling me --- go send this buffer
> yourself!

Hmm, I noticed that too, but I thought it was a change in python-mode
itself. I just got used to it. I didn't bother trying to chase it down.

To start a new process, try C-u C-c C-p .

Re: on GNU EMACS's python-mode, loading entire buffer

<86sflezcpt.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19376&group=comp.lang.python#19376

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!M+UzZZ6ThUS76UHmDkoHCg.user.46.165.242.91.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.python
Subject: Re: on GNU EMACS's python-mode, loading entire buffer
Date: Mon, 29 Aug 2022 23:28:46 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86sflezcpt.fsf@levado.to>
References: <86y1v6zzf3.fsf@levado.to> <87zgfmyj0f.fsf@nightsong.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="37228"; posting-host="M+UzZZ6ThUS76UHmDkoHCg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:IvKwcDw9nOQleiYF7Ugy56uNEc0=
 by: Meredith Montgomery - Tue, 30 Aug 2022 02:28 UTC

Paul Rubin <no.email@nospam.invalid> writes:

> Meredith Montgomery <mmontgomery@levado.to> writes:
>> Now in 27.1, things are different. I say C-c C-c and it tells me to
>> start the process with C-c C-p. I mean --- is that the most polite
>> thing to do? I feel like it's telling me --- go send this buffer
>> yourself!
>
> Hmm, I noticed that too, but I thought it was a change in python-mode
> itself. I just got used to it. I didn't bother trying to chase it down.

These little conveniences are so important. :-)

> To start a new process, try C-u C-c C-p .

Oh, thank you!

Re: on GNU EMACS's python-mode, loading entire buffer

<868rn4zg3m.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19398&group=comp.lang.python#19398

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!o5MaPRqzoHCfrMs/zIGcfw.user.46.165.242.91.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.python
Subject: Re: on GNU EMACS's python-mode, loading entire buffer
Date: Wed, 31 Aug 2022 10:40:13 -0300
Organization: Aioe.org NNTP Server
Message-ID: <868rn4zg3m.fsf@levado.to>
References: <86y1v6zzf3.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="40977"; posting-host="o5MaPRqzoHCfrMs/zIGcfw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:uYSXpSm9K2lyaeSYzZoJsOBcmGo=
 by: Meredith Montgomery - Wed, 31 Aug 2022 13:40 UTC

Meredith Montgomery <mmontgomery@levado.to> writes:

[...]

> I would also be interested in a command that restarts the REPL afresh
> and reloads my buffer --- sort of like keyboard's [F5] of the IDLE.

A partial solution for this is the following procedure.

--8<---------------cut here---------------start------------->8---
(defun python-revert-and-send-buffer-to-repl ()
"Revert current buffer and sends it to the Python REPL."
(interactive)
(revert-buffer "ignore-auto-no" "no-confirm")
(python-shell-send-buffer))
--8<---------------cut here---------------end--------------->8---

We can map this to the F5-key and that improves things. But a restart
of the REPL would be the ideal. (Sometimes we really want to start
afresh. Sometimes. Most often we don't want that.)

Re: on GNU EMACS's python-mode, loading entire buffer

<86ilm2ncqs.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19423&group=comp.lang.python#19423

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!vI7O8iMkFNFLei4SFZylhA.user.46.165.242.91.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.python
Subject: Re: on GNU EMACS's python-mode, loading entire buffer
Date: Sun, 04 Sep 2022 16:47:07 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86ilm2ncqs.fsf@levado.to>
References: <86y1v6zzf3.fsf@levado.to> <868rn4zg3m.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="45806"; posting-host="vI7O8iMkFNFLei4SFZylhA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:BZ8ih+l7E6YHgdgUdGyPg4wL8O0=
 by: Meredith Montgomery - Sun, 4 Sep 2022 19:47 UTC

Meredith Montgomery <mmontgomery@levado.to> writes:

> Meredith Montgomery <mmontgomery@levado.to> writes:
>
> [...]
>
>> I would also be interested in a command that restarts the REPL afresh
>> and reloads my buffer --- sort of like keyboard's [F5] of the IDLE.
>
> A partial solution for this is the following procedure.
>
> (defun python-revert-and-send-buffer-to-repl ()
> "Revert current buffer and sends it to the Python REPL."
> (interactive)
> (revert-buffer "ignore-auto-no" "no-confirm")
> (python-shell-send-buffer))
>
> We can map this to the F5-key and that improves things. But a restart
> of the REPL would be the ideal. (Sometimes we really want to start
> afresh. Sometimes. Most often we don't want that.)

It's not easy to restart the REPL. You can send "quit()" to it and
invoke run-python again interactively by typing out one command after
another, but if you write a procedure such as this one below, it doesn't
work: it gives me the impression that there's a timing issue, that is,
perhaps the procedure is too fast and something happens before it
should.

(defun python-save-send-buffer-to-repl ()
(interactive)
(save-buffer)
(python-shell-send-string "quit()")
(run-python)
(python-shell-send-buffer)
(python-shell-switch-to-shell))

Re: on GNU EMACS's python-mode, loading entire buffer

<mailman.495.1664449587.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19600&group=comp.lang.python#19600

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: stephen....@gmx.net (Stephen Berman)
Newsgroups: comp.lang.python
Subject: Re: on GNU EMACS's python-mode, loading entire buffer
Date: Thu, 29 Sep 2022 13:06:25 +0200
Lines: 52
Message-ID: <mailman.495.1664449587.20444.python-list@python.org>
References: <86y1v6zzf3.fsf@levado.to> <868rn4zg3m.fsf@levado.to>
<86ilm2ncqs.fsf@levado.to> <87wn9mwiby.fsf@gmx.net>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de cZfL73u5pzaYFMkEwHDD9gaR3RXGP0pXzi6PNqExQKcA==
Return-Path: <stephen.berman@gmx.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="1024-bit key; unprotected key"
header.d=gmx.net header.i=@gmx.net header.b=OUwsE275;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '2022': 0.05; 'issue.':
0.05; 'subject:python': 0.06; 'partial': 0.07; 'received:212.227':
0.07; 'sun,': 0.07; 'restart': 0.09; 'timing': 0.09; 'writes:':
0.09; 'afresh.': 0.16; 'another,': 0.16; 'ideal.': 0.16; 'idle.':
0.16; 'improves': 0.16; 'invoke': 0.16; 'procedure': 0.16;
'received:212.227.15': 0.16; 'subject:GNU': 0.16;
'subject:loading': 0.16; 'typing': 0.16; 'work:': 0.16; 'wrote:':
0.16; 'python': 0.16; 'to:addr:python-list': 0.20; 'command':
0.23; 'skip:p 30': 0.23; '>>>': 0.28; 'header:User-Agent:1': 0.30;
'seem': 0.31; "doesn't": 0.32; 'sep': 0.32; 'but': 0.32; 'work.':
0.34; 'header:In-Reply-To:1': 0.34; 'following': 0.35; 'really':
0.37; "it's": 0.37; 'steve': 0.39; 'skip:( 30': 0.40; 'something':
0.40; 'want': 0.40; "there's": 0.61; 'gives': 0.62;
'received:212': 0.62; 'send': 0.63; 'interested': 0.68; 'easy':
0.74; 'happens': 0.84; 'meredith': 0.84; 'me:': 0.91;
'received:89': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net;
s=badeba3b8450; t=1664449585;
bh=l+JbiiDEyX4E7Ph7v8XS3RFSqKOEDXC5aIibym2OBy8=;
h=X-UI-Sender-Class:From:To:Subject:In-Reply-To:References:Date;
b=OUwsE275r7MciX6nXyqWyrsblOBGALAq7uXcbL6AaUEFWDPyWyRcclPB/chHSxvPp
SG1+jrJB8+3VAwmQrfbIQoozNptfzMFwAQYu5FyeiFb6WyhC+ymY09OsKPfaiUUukb
gAA4dmtxSQeN4MhdvLQPbyyrSBhEH5MzO501K3tM=
X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c
In-Reply-To: <86ilm2ncqs.fsf@levado.to> (Meredith Montgomery's message of
"Sun, 04 Sep 2022 16:47:07 -0300")
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
X-Provags-ID: V03:K1:g3M/dI0MBss+TiqmEdUb6D98TaSjdy+rco/F3N9WQHOlf6rhb+f
iMCSZ56I7gPcyDF8qZdvc8pPRUI/QVUSE3RQsYyuhgW3mmsMFyrMmsy6xY2BSDQf2L924mo
i1ov9ee2GKs6R7oKty6OEyhiMSXXvOoS0XKNbUqQMYKvue7PX93NQQ4EkoV1mUTAGld5ZeS
SS9Vxln2iadNKVI/dy27Q==
X-Spam-Flag: NO
X-UI-Out-Filterresults: notjunk:1;V03:K0:pDFvCy10l80=:lS1G4Rei97rBFNLLFHo6Ga
tsamB0NMNQxDsAdymRMS8gRkstNPKHVSoFpz9zC8Y0q1pHat5iNvgPZfnsdZGMvuG0t9REdHO
He5ar0V9KYQIsbZBcGq0Y69tNSlrrQgQVzCXYgudVAoaWL0VEatvjkuP2sOQeXmcHjyI78QB0
fATm+1TjmouwConJtEF0c/B1Al7/s/YPvuQzlQV0oicMJzfo+4ZVstSK5R5+/bvTwLoTSs8lb
rZq3BTlNH7mJJPZkV2DDw3swH+SDH1MDjngejkYHdLuhkwSVy+jzs2VEO1t7L5rlLILuoskQ6
q5IPzyyrupZd8iU6z3PHSLvPp6LfpGeyoEWDb0iAnDvxGZlZD05s4tNHwFvVgz5rHPesuquJO
E8X6lM4ECHtzdEf1fe4uJeOhj+07ZhfygZdxB/nL3YYSpEUAB/2NYi6U2utZwATBMpqNR/2+n
IY90lk5Q1jxDpp9P/5w6x/0vVoRH7DEB3Fvi+AWAeZAvI2F6Py/ZVjECe3DfaLqkk/SbC2YGC
Jwq2mVCahx1IRn3Ws3k9L2aaW62dKaNdcVXwAG2KxYubZczJRn12anU3sOYcegNFTeiwKQhAi
Lsw65fYVG0nv64vmZFXOXQImUOxWOrFjlxxu+Y9hv+n2Bj9rEkfqMe4U9vpFswgAP/l9qS4gF
+ohgDcu8kqMNlG4e+AgMXZ47gc8GgsOPVYRP6jFV5yUGofff4gHgZxzDGo3E8cOjVCKdBFHr9
jqDrxGo1L4mP5sEmtLoPwz/wkT8Ge827ketuxVT4mZQCwoZGu7j1qA5tmL7g4ULio21GmAXti
b4lMx+lpkzhf3g7mc97SSfXJu56se8JiVPYJUJGOvYFc6Yv3l0F78i45BQrTNBFdg4u8CQIz2
D13y3DdakynER4xLtISa8eMLi5heh6pR22O+WK6pUneIy2nH+0EoqSGWs58Voafn92PBrsOVa
WgjvvQ0lUuA7GzuCP7JrSrvYQgpCY/sgdNePdkXDJaYo9vR/tBywBENuhH8lpxQ2Tev8aZ0n8
gIVvCMFDII3URGnjhddQQhM9dqKb4IQacC1g+pZq6ux4riqFe3rP5qLOYzGWEWdNPuW6CwoEu
IYlOXDxwXiDcs92W9/0D8rnSTYEDlJKGE0WoPWQ3WVSCuKyfeByZWWu++A6YExEKA4BRVcx/X
j4vgodfdKXfTYLy8oEL+IcHceT
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <87wn9mwiby.fsf@gmx.net>
X-Mailman-Original-References: <86y1v6zzf3.fsf@levado.to>
<868rn4zg3m.fsf@levado.to>
<86ilm2ncqs.fsf@levado.to>
 by: Stephen Berman - Thu, 29 Sep 2022 11:06 UTC

On Sun, 04 Sep 2022 16:47:07 -0300 Meredith Montgomery <mmontgomery@levado.to> wrote:

> Meredith Montgomery <mmontgomery@levado.to> writes:
>
>> Meredith Montgomery <mmontgomery@levado.to> writes:
>>
>> [...]
>>
>>> I would also be interested in a command that restarts the REPL afresh
>>> and reloads my buffer --- sort of like keyboard's [F5] of the IDLE.
>>
>> A partial solution for this is the following procedure.
>>
>> (defun python-revert-and-send-buffer-to-repl ()
>> "Revert current buffer and sends it to the Python REPL."
>> (interactive)
>> (revert-buffer "ignore-auto-no" "no-confirm")
>> (python-shell-send-buffer))
>>
>> We can map this to the F5-key and that improves things. But a restart
>> of the REPL would be the ideal. (Sometimes we really want to start
>> afresh. Sometimes. Most often we don't want that.)
>
> It's not easy to restart the REPL. You can send "quit()" to it and
> invoke run-python again interactively by typing out one command after
> another, but if you write a procedure such as this one below, it doesn't
> work: it gives me the impression that there's a timing issue, that is,
> perhaps the procedure is too fast and something happens before it
> should.
>
> (defun python-save-send-buffer-to-repl ()
> (interactive)
> (save-buffer)
> (python-shell-send-string "quit()")
> (run-python)
> (python-shell-send-buffer)
> (python-shell-switch-to-shell))

It does seem like a timing issue. This works for me:

(defun python-save-send-buffer-to-repl ()
(interactive)
(save-buffer)
(python-shell-send-string "quit()")
(sit-for 0.1)
(run-python)
(python-shell-send-buffer)
(python-shell-switch-to-shell))

But if I decrease the wait to 0.05 it doesn't work.

Steve Berman

Re: on GNU EMACS's python-mode, loading entire buffer

<867d1gesp2.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19640&group=comp.lang.python#19640

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!yop09xhwaKy9YXrWd0pu4w.user.46.165.242.91.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.python
Subject: Re: on GNU EMACS's python-mode, loading entire buffer
Date: Mon, 03 Oct 2022 14:13:29 -0300
Organization: Aioe.org NNTP Server
Message-ID: <867d1gesp2.fsf@levado.to>
References: <86y1v6zzf3.fsf@levado.to> <868rn4zg3m.fsf@levado.to>
<86ilm2ncqs.fsf@levado.to> <87wn9mwiby.fsf@gmx.net>
<mailman.495.1664449587.20444.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="29833"; posting-host="yop09xhwaKy9YXrWd0pu4w.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:lxTOUzK+f82Al9gChOdLc+0nkNY=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Mon, 3 Oct 2022 17:13 UTC

Stephen Berman <stephen.berman@gmx.net> writes:

> On Sun, 04 Sep 2022 16:47:07 -0300 Meredith Montgomery
> <mmontgomery@levado.to> wrote:
>
>> Meredith Montgomery <mmontgomery@levado.to> writes:
>>
>>> Meredith Montgomery <mmontgomery@levado.to> writes:
>>>
>>> [...]
>>>
>>>> I would also be interested in a command that restarts the REPL afresh
>>>> and reloads my buffer --- sort of like keyboard's [F5] of the IDLE.
>>>
>>> A partial solution for this is the following procedure.
>>>
>>> (defun python-revert-and-send-buffer-to-repl ()
>>> "Revert current buffer and sends it to the Python REPL."
>>> (interactive)
>>> (revert-buffer "ignore-auto-no" "no-confirm")
>>> (python-shell-send-buffer))
>>>
>>> We can map this to the F5-key and that improves things. But a restart
>>> of the REPL would be the ideal. (Sometimes we really want to start
>>> afresh. Sometimes. Most often we don't want that.)
>>
>> It's not easy to restart the REPL. You can send "quit()" to it and
>> invoke run-python again interactively by typing out one command after
>> another, but if you write a procedure such as this one below, it doesn't
>> work: it gives me the impression that there's a timing issue, that is,
>> perhaps the procedure is too fast and something happens before it
>> should.
>>
>> (defun python-save-send-buffer-to-repl ()
>> (interactive)
>> (save-buffer)
>> (python-shell-send-string "quit()")
>> (run-python)
>> (python-shell-send-buffer)
>> (python-shell-switch-to-shell))
>
> It does seem like a timing issue. This works for me:
>
> (defun python-save-send-buffer-to-repl ()
> (interactive)
> (save-buffer)
> (python-shell-send-string "quit()")
> (sit-for 0.1)
> (run-python)
> (python-shell-send-buffer)
> (python-shell-switch-to-shell))
>
> But if I decrease the wait to 0.05 it doesn't work.

Interesting. I can't reproduce this at all. No matter how long I sit,
I always get a similar ``crash''. Here's what happens for me with your
procedure, sitting for even 5 seconds. I'm adding a 5-second delay
after quitting and after running the REPL.

--8<---------------cut here---------------start------------->8---
(defun python-save-send-buffer-to-repl ()
"Save current buffer and sends it to the Python REPL."
(interactive)
(save-buffer)
(python-shell-send-string "quit()")
(sit-for 5)
(run-python)
(sit-for 5)
(python-shell-send-buffer)
(python-shell-switch-to-shell))
--8<---------------cut here---------------end--------------->8---

When the REPL comes up, it looks fine. When I try to see if a
hello-procedure was defined, I get the following:

--8<---------------cut here---------------start------------->8---
>>>
Process Python finished
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:/Users/mer/AppData/Local/Temp/pyoUKuUx", line 1
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)] on win32
^
SyntaxError: invalid decimal literal
>>> >>> hello
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'hello' is not defined. Did you mean: 'help'?
>>>
--8<---------------cut here---------------end--------------->8---

You see? It seems that the Python's banner is sent to the REPL,
somehow. I actually see it being sent sometimes --- I see in the
minibuffer that the string ``Python 3.10.6 (tags/v3.10.6:9c7b4bd[...]''
was sent to the REPL.

Somehow my GNU EMACS is reading the banner and sending it back to the
REPL as if it were code in my file. My file contained just this:

--8<---------------cut here---------------start------------->8---
# -*- mode: python; python-indent-offset: 2 -*-
def hello():
return 1
--8<---------------cut here---------------end--------------->8---

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor