Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8567243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:50:15+00:00 2026-06-11T17:50:15+00:00

I’ve been searching for quite a while for a solution about this but no

  • 0

I’ve been searching for quite a while for a solution about this but no dice.

Edit: I didn’t point out that I’m trying to make a chat server. So people log in, their id gets appended to a users and a listeners list. And they start chatting. But when one of them tries to close the tab or browser the user will never be deleted out of both lists, so he/she stays logged in.

Edit2: I thought that the numbering above was a little confusing so I posted the part in the script as well at the bottom.

So far I’ve tried the on_connection_close() function (which doesn’t ever get fired, I don’t know why), the on_finish() function (which gets fired every time when a finish() is called) so that doesn’t fit the bill either.

Now I’ve come up with a little bit of a solution which involves the on_finish() function:

  1. Whenever the UpdateHandler class’ post() function gets called then self.done = 0 is set.
  2. Just before the finish() function gets fired I set self.done = 1.
  3. Now the on_finish() function gets called and I print self.done on the console and it’s 1.
  4. In the same on_finish() function I do an IF self.done = 1 statement, as expected it returns TRUE and Tornado’s io_loop.add_timeout with the parameters time.time()+3 (so that it sleeps for 3 seconds to make sure if the user navigated to another page within the website or completely went away from the website) and the callback that eventually is going to be called.
  5. After the 3 seconds I want to check whether self.done still equals 1 or if the user is still on the website then sure enough it will be 0.

btw, every 30 seconds the server finishes the connection and then sends the user a notification to initiate a new connection so that the connection never times out on it’s own.
When the client closes the browser and the 30 second long timeout expires then the server tries to send a notification, if the client was still on my website then it would initiate a new connection thus calling the post() function in the UpdateHandler class I mentioned above thus setting the variable self.done back to 0. (That’s why I gave the io_loop.add_timeout a margin of 3 seconds.)

Now that that’s taken care of I wanted to go ahead and try and see how it works.
I started the server and opened up a browser navigated to the right url and watched how the server responded (by placing a few print statements in the script). When the user stays connected I can see that after the post() call (which shows at that time self.done = 0) it sleeps for 3 seconds, and then the callback function gets called but this one prints self.done = 1 which is strange.

I know this is not the most efficient way but it’s the only solution I could come up with, which didn’t even work as expected.

Conclusion:

I hope someone has a good alternative or maybe even a point in my theory that I missed which breaks the whole thing.
I really would like to know how to let Tornado know that the client closed the browser without waiting for the 30 second timeout to finish.
Maybe with pinging the open connection or something. I looked into TORNADIO for a little bit but didn’t like it that much. I want to do this in pure Tornado if it’s possible of course.

I’ll submit the code ASAP, I’ve been trying for like half an hour looking at ‘How to Format’ etc. but when I try to submit my edit it gives an error.

  • Your post appears to contain code that is not properly formatted as
    code. Please indent all code by 4 spaces using the code toolbar
    button or the CTRL+K keyboard shortcut. For more editing help, click
    the [?] toolbar icon.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:50:16+00:00Added an answer on June 11, 2026 at 5:50 pm

    I’ve been having this issue for like 5 – 6 days and finally found out what the problem is, well.. not exactly actually but it’s solved! I’ve been searching on the internet but found nothing. I told in the above post that I do remember it working when I tried the same script a couple months ago, but I never mentioned using nginx back then. I’ve been struggling with Apache + mod_proxy but I don’t know what the issue is with apache but when I tried nginx this time again it just worked!

    If you have the same issue (on_connection_close not getting fired) “TRY” nginx. Thanks for your help too @Nikolay.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.