0

I created a web application (Django) for my team in which the files are first converted to .txt from PDF and then the meaningful information is captured in the excel sheet. When user submits a request then there is some process starts on my command line as well(Server hosted on my PC). Problem is when the user closes his session (tab), but the process is still running on my command line.

As this server will run locally(My Computer) how will I know that the user has closed his browser(session) and close my server accordingly?

python
  • 4,403
  • 13
  • 56
  • 103
  • You should not be running a production app on your PC. Is Heroku or AWS not an option? – kylieCatt Jun 17 '15 at 02:23
  • This web app will run locally because I have created this for my team and it needs to access the shared drive. – python Jun 17 '15 at 02:35
  • You just described a webapp with online storage – kylieCatt Jun 17 '15 at 11:36
  • Shared drive is local and server will run on my PC. It is a simple application but I want to close my server when the user closes his tab(session). – python Jun 17 '15 at 14:33
  • As far as I know closing a tab != to closing a session depending on how you handle a session. How are you running the app? – kylieCatt Jun 17 '15 at 14:53
  • The app is running on my PC (python manage.py runserver if you know django) and the local drive is accessible to my whole team. The app will take input from the local drive and produce output there. Since the files are confidential we cannot run this app in aws , herouku or whatever since the app deployed on cloud cannot access user's local drive. – python Jun 19 '15 at 15:46
  • You should absolutely not being using `runserver` to serve your app. It meant for development work only and not for use as a production server. It's not secure and I'm fairly certain it's single threaded. So I'm assuming that when one user closes a tab and the process stays open no one else can use the app. – kylieCatt Jun 19 '15 at 15:52
  • The app is build for only 2 members and it is not for production. Yes when the user closes his tab the app is still running. Security and multi-threading is not a issue here. – python Jun 19 '15 at 17:00
  • I want to close the session created by the user when his tab is closed. Do you think it is possible? – python Jun 19 '15 at 17:01
  • No: http://stackoverflow.com/questions/1921941/close-kill-the-session-when-the-browser-or-tab-is-closed – kylieCatt Jun 19 '15 at 18:37

1 Answers1

0

Taken from link

When a session is created b/w the browser and your server (Jboss and liferay in this case), it puts a cookie on the client's browser that identifies the session. That cookie is probably set to expire when the browser closes. So when you re-open, the browser no longer has that cookie, so it can't identify with any session. So, from a technical sense, the session on the server side isn't closed technically. That happens when the session expires, usually a set period of time from inactivity. For a session, there are usually three ways it gets destroyed on the server side - a logout (which the app destroys the session), a period of inactivity (could be 15 minutes or whatever), or a "hard" timeout, you may want your users to always re-login every 8 hours for instance.

So in other words, even if the browser closes, the server doesn't know it and the session is alive and well until it expires. Login is only required bc/ the cookie is flushed when the browser closes. Now, when a tab closes, the browser doesn't necessarily close so it still has that cookie.

One way to do what you want would be to have a Javascript hook that gets called (like an event) when the tab closes. This javascript could call a servlet or web service to let it know to destory the session.

python
  • 4,403
  • 13
  • 56
  • 103