Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

209
Visualizações
Triggering a python function when tab closes with flask

I'm trying to create a modern looking GUI so I decided to setup a simple flask app. Eventually, I want to pack the app up in a .exe file, so I want to start the server and open a web-browser when I start the flask app, and quit the server when I close the tab. My question is:

Is there any way to trigger a python function that quits the flask server when I close the tab?

Thank you for the help in advance!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can add an event listener to beforeunload event and send a request when the tab is about to close.

window.onbeforeunload = () => fetch('/stop');

When you confirm it, the request is sent, and you can shut down the server inside the handler.

The only downside is that the browser shows a popup, confirming if you really want to leave.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda