Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!