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

  • SEARCH
  • Home
  • 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 8397185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:43:33+00:00 2026-06-09T20:43:33+00:00

I’m writing a chat server in Python for an assignment. However, I am having

  • 0

I’m writing a chat server in Python for an assignment. However, I am having an issue shutting down the server. Here’s what’s happening:

When a client connects, I spawn two threads: readThread and writeThread. readThread is responsible for reading data from the client and printing it to stdout, and writeThread is responsible for reading a message from stdin and sending it to the client.

When the client sends 'EXIT', I want to shutdown the server. My writeThread runs in a loop like this:

def write(self) :
        while self.dowrite :
            data = sys.stdin.readline().strip();            
            self.conn.send(data);
        print 'WriteThread loop ended';

Now, when I receive EXIT, I set dowrite to false, but, of course, that doesn’t break the while loop because of the blocking call sys.stdin.readline().strip().

So, what happens is: to disconnect, the client needs to send EXIT, and then I need to hit return on the console. Is there any way I can work around this, so that when the client sends the exit message, I immediately break out of the while loop in write().

EDIT
How it comes together:

The main thread spawns two threads : read and write, and then waits (joins) for read to finish. Read finishes when it reads EXIT. As soon as the read thread ends, the main thread continues and sets dowrite to false in the write thread, which should end the write loop, but that can only happen once the while loop iterates one more time.

  • 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-09T20:43:34+00:00Added an answer on June 9, 2026 at 8:43 pm

    Make child threads to be daemons:

    t.daemon = True
    

    Daemon threads will stop if your program exits.

    You could use an event to notify other threads about it. In the thread where the event occured:

    event.set() # event occurred
    

    In other threads:

    event.wait() # wait for event
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am writing an app with both english and french support. The app requests
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.