Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

behavior of KeyboardInterrupt?

Aperta
#30 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
julia, matplotlib, python

Direzione di ricerca

Riproduci il comportamento di Windows Ctrl-C con PythonPlot, il ciclo while true e la chiamata di plotting mostrata nell’issue. Inizia da src/pygui.jl:199 e ispeziona lo stack dei timer di PythonCall e tkinter; confronta il risultato con il backend GR. Il lavoro è completato quando è possibile interrompere il calcolo Julia senza compromettere le chiamate PythonPlot successive.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

During an interactive session where I am variously running computations and plotting things, when I try to keyboard interrupt a running computation, Python apparently gets interrupted instead; for example, notice what happens when I hit Ctrl-C during a while true block:

julia> using PythonPlot

julia> plot(range(0, 1, 101).^2)
Python: [<matplotlib.lines.Line2D object at 0x0000022445A5FF50>]

julia> while true # surrogate for some long computation that I decide I want to interrupt
           5+2
           sleep(0.1)
       end
Error in Timer:
Python: KeyboardInterrupt:
Python stacktrace:
 [1] __getattr__
   @ tkinter C:\Users\zor_q\.julia\environments\v1.9\.CondaPkg\env\Lib\tkinter\__init__.py:2408
Stacktrace:
 [1] pythrow()
   @ PythonCall C:\Users\zor_q\.julia\packages\PythonCall\qTEA1\src\err.jl:94
 [2] errcheck
   @ C:\Users\zor_q\.julia\packages\PythonCall\qTEA1\src\err.jl:10 [inlined]
 [3] pygetattr(x::PythonCall.Py, k::String)
   @ PythonCall C:\Users\zor_q\.julia\packages\PythonCall\qTEA1\src\abstract\object.jl:60
 [4] getproperty(x::PythonCall.Py, k::Symbol)
   @ PythonCall C:\Users\zor_q\.julia\packages\PythonCall\qTEA1\src\Py.jl:261
 [5] (::PythonPlot.var"#9#10"{PythonCall.Py, PythonCall.Py, PythonCall.Py})(async::Timer)
   @ PythonPlot C:\Users\zor_q\.julia\packages\PythonPlot\f591M\src\pygui.jl:199
 [6] macro expansion
   @ .\asyncevent.jl:281 [inlined]
 [7] (::Base.var"#702#703"{PythonPlot.var"#9#10"{PythonCall.Py, PythonCall.Py, PythonCall.Py}, Timer})()
   @ Base .\task.jl:134

Meanwhile, the while true block continues running. If it were a computation that came to an end at some point, all future plotting would fail (I assume because the background Python process is no longer running?).

Is this the expected behavior? I would have hoped that the execution of the while true block would have been interrupted and Python would have been left alone.

For comparison, when using GR, it's the while true block that gets interrupted:

julia> using Plots # default backend is GR

julia> plot(range(0, 1, 101).^2) # plot window pops up

julia> while true # surrogate for long computation that I decide I want to interrupt
           5+2
           sleep(0.1)
       end
ERROR: InterruptException:
Stacktrace:
 [1] poptask(W::Base.IntrusiveLinkedListSynchronized{Task})
   @ Base .\task.jl:974
 [2] wait()
   @ Base .\task.jl:983
 [3] wait(c::Base.GenericCondition{Base.Threads.SpinLock}; first::Bool)
   @ Base .\condition.jl:130
 [4] wait
   @ .\condition.jl:125 [inlined]
 [5] _trywait(t::Timer)
   @ Base .\asyncevent.jl:138
 [6] wait
   @ .\asyncevent.jl:155 [inlined]
 [7] sleep
   @ .\asyncevent.jl:240 [inlined]
 [8] top-level scope
   @ .\REPL[3]:3

julia> plot(range(0, 1, 101).^2) # still plots successfully

julia> backend()
Plots.GRBackend()
Lingua principale
Julia
Stelle
85
Fork
9
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di JuliaPy/PythonPlot.jl

Tutte le issue di JuliaPy/PythonPlot.jl

Issue simili

Altre issue su Julia

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.