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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:04:23+00:00 2026-05-26T07:04:23+00:00

Given this Python program: # commented out code are alternatives I tried that don’t

  • 0

Given this Python program:

# commented out code are alternatives I tried that don't work.

from multiprocessing import Process, Queue
#from multiprocessing import Process, JoinableQueue as Queue

def start_process(queue):
    # queue.cancel_join_thread()
    while True:
        print queue.get()

if __name__ == '__main__':
    queue = Queue()
    # queue.cancel_join_thread()

    process = Process(target=start_process, args=(queue,))
    process.start()

    queue.put(12)
    process.join()

When I kill this program with CTRL-C, this happens:

$> python queuetest.py
12
^CTraceback (most recent call last):
  File "queuetest.py", line 19, in <module>
    process.join()
  File ".../python2.7/multiprocessing/process.py", line 119, in join
    res = self._popen.wait(timeout)
Process Process-1:
  File ".../python2.7/multiprocessing/forking.py", line 122, in wait
Traceback (most recent call last):
    return self.poll(0)
  File ".../python2.7/multiprocessing/forking.py", line 107, in poll
    pid, sts = os.waitpid(self.pid, flag)
  File ".../python2.7/multiprocessing/process.py", line 232, in _bootstrap
KeyboardInterrupt
    self.run()
  File ".../python2.7/multiprocessing/process.py", line 88, in run
    self._target(*self._args, **self._kwargs)
  File "queuetest.py", line 9, in start_process
    print queue.get()
  File ".../python2.7/multiprocessing/queues.py", line 91, in get
    res = self._recv()
KeyboardInterrupt

.. how do I properly terminate the two processess on signal ?

What I want to achieve: In my non-minimal program the second process holds a SocketServer and needs an additional interactive command line interface.

  • 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-05-26T07:04:23+00:00Added an answer on May 26, 2026 at 7:04 am

    A solution is to send a specific message (eg ‘exit’ string in my sample) via queue, to terminate the worker(child process) normal. As the CTRL-C signal is send to all children, we need to ignored it.
    Here is sample code:

    from multiprocessing import Process, Queue
    
    def start_process(queue):
      while True:
        try:
            m = queue.get()
            if m == 'exit':
                print 'cleaning up worker...'
                # add here your cleaning up code
                break
            else:
                print m
        except KeyboardInterrupt:
            print 'ignore CTRL-C from worker'
    
    
    if __name__ == '__main__':
      queue = Queue()
    
      process = Process(target=start_process, args=(queue,))
      process.start()
    
      queue.put(12)
    
      try:
        process.join()
      except KeyboardInterrupt:
        print 'wait for worker to cleanup...'
        queue.put('exit')
        process.join()
    
        ## or to kill anyway the worker if is not terminated after 5 seconds ...
        ## process.join(5)
        ## if process.is_alive():
        ##     process.terminate()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was given this Python code that would calculate an MD5 value for any
From Python docs: sys.excepthook(type, value, traceback) This function prints out a given traceback and
I have this code from Learn Python The Hard Way and I need to
This exercise is taken from Google's Python Class : D. Given a list of
given this xml file, i would like to extract the data out from it.
How do I get a tuple/list element given a condition in python? This occurs
I have a third-party GUI program that I'm wrapping with a Python class (using
Coming to Python from Java, I've been told that factories are not Pythonic. Thus,
I have a Python program that runs a series of experiments, with no data
Working on some code and I'm given the error when running it from the

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.