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 8529267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:59:36+00:00 2026-06-11T08:59:36+00:00

I have a socket server that used threading to open a thread for each

  • 0

I have a socket server that used threading to open a thread for each client that connects.
I also have two other threads that run constantly that are doing maintenance operations.

Basically there is the main thread plus two children running constantly, plus one child for each client that connects.

I want to be able to terminate or restart safely.

I would like to be able to trigger a termination function somehow that would instruct all child processes to terminate safely and then the parent could exit.

Any ideas?

Please do not suggest to connect as a client and send a command that would trigger that.
Already thought of it.

I am looking for a way to do this by executing something in the console.

The python socket server runs as a system service and would like to implement the termination in the init script.

  • 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-11T08:59:37+00:00Added an answer on June 11, 2026 at 8:59 am

    The best way to do this is setup a signal handler in your main thread. This can be done using the signal module. See: http://docs.python.org/library/signal.html. A good way would be to trap the CTRL-C signal (SIGINT).

    Please note that the signal handler can also be a class method, so you do not have to use a global method (it took me a while to discover that).

     def __init__(self):
         signal.signal(signal.SIGINT, self.just_kill_me)
    
     def just_kill_me(self, sig, frame):
         self.stopped = True
         for t in self.threads:
             t.join()
    

    It is not possible to send the equivalent of a kill signal to a thread. Instead you should set a flag that will signal the children to stop.

    Your child threads should run in a loop, periodically checking if the parent requests them to stop.

    while not parent.stopped:
        do_some_maintenance_work
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Android client app that communicates with server using Socket . On my
I have a process that must create and close threads on demand. Each thread
I have to create an sample code that connect to a socket server, and
I have developed a Java server using Eclipse that accepts TCP socket connection from
I have c++ socket server and android client. Server constantly sends data to the
I have created my web socket server and client using this simple tutorial here
I have a program (written in C/C++) that behaves as a socket server. I'd
I have a simple IRC socket that is used to communicate with servers for
I have a trivial secure socket server-client program. For the server certificates, I created
I have a client server situation where the client opens a TCP socket to

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.