[MNT]: Event loop and timer consistency

Aberta
#32,352 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
5/5
Tempo estimado
Mais de uma semana
Facilidade para iniciantes
38/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
python

Direção de pesquisa

Comece rastreando plt.show(), FigureCanvas.start_event_loop(), stop_event_loop(), flush_events(), new_timer() e Timer nos backends interativos e, em seguida, analise as issues relacionadas #29062, #31858 e #31968. Considera-se concluído quando o comportamento de worker threads e event loops for consistente entre os backends e a política ainda não resolvida entre deprecation e erro imediato estiver definida.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

API: consistency Maintenance status: needs comment/discussion topic: backends
Summary

Right now, our methods related to event loops and timers have inconsistent behavior across interactive backends. When called on a worker thread, or when called in a specific order, these methods will often raise internal errors from the wrapped GUI framework. In several cases, they will crash the process entirely.

The exact behavior can vary depending on platform. For example, pyplot.show() on a worker thread crashes in GTK+macOS, but works in GTK+Linux as long as you are very careful.

Proposed fix

I propose that we unify the behavior across all interactive backends by raising an error when the following are called on a worker thread:

plt.show()
FigureCanvas.start_event_loop()
FigureCanvas.stop_event_loop()
FigureCanvas.flush_events()
FigureCanvas.new_timer()
Any method of Timer (note: backends could still use Timers internally as needed)

Additionally, for consistency:

  • plt.show() and FigureCanvas.start_event_loop() should raise an error if an event loop is already running - this matches the existing behavior of most backends.
  • FigureCanvas.stop_event_loop() should stop the event loop if it is running, regardless of how that event loop was started. If an event loop isn't running, it should simply return (the existing behavior of most backends).
  • All of the changes in #29062. I'm still auditing Timer behavior across backends - I believe that there are cases that this PR doesn't yet cover.

For now, we could add a deprecation message if the behavior doesn't already raise or crash. For behavior that currently crashes, I'm not sure of our policy. Would we print a deprecation message and then crash? Or would we raise an error now without a deprecation cycle?

Related issues: #31858, #31968

Linguagem predominante
Python
Estrelas
23.5k
Forks
8.6k
Merge médio
1d 19h
PRs com merge (30d)
64

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de matplotlib/matplotlib

Todas as issues de matplotlib/matplotlib

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.