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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:15:25+00:00 2026-06-17T12:15:25+00:00

When you execute a python script, does the process/interpreter exit because it reads an

  • 0

When you execute a python script, does the process/interpreter exit because it reads an EOF character from the script? [i.e. is that the exit signal?]

The follow up to this is how/when a python child process knows to exit, namely, when you start a child process by overriding the run() method, as here:

class Example(multiprocessing.Process):
    def __init__(self, task_queue, result_queue):
        multiprocessing.Process.__init__(self)
        self.task_queue = task_queue
        self.result_queue = result_queue

    def run(self):
        while True:
            next_task = self.task_queue.get()
            if next_task is None:
                print '%s: Exiting' % proc_name
                break
#more stuff...[assume there's some task_done stuff, etc]

if __name__ == '__main__':
    tasks = multiprocessing.JoinableQueue()
    results = multiprocessing.Queue()

    processes = [ Example(tasks, results)
                  for i in range(5) ]
    for i in processes:
        i.start()
#more stuff...like populating the queue, etc.

Now, what I’m curious about is: Do the child processes automatically exit upon completion of the run() method? And if I kill the main thread during execution, will the child processes end immediately? Will they end if their run() calls can complete independently of the status of the parent process?

  • 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-17T12:15:26+00:00Added an answer on June 17, 2026 at 12:15 pm

    Yes, each child process terminates automatically after completion of the run method, even though I think you should avoid subclassing Process and use the target argument instead.

    Note that in linux the child process may remain in zombie state if you do not read the exit status:

    >>> from multiprocessing import Process
    >>> def target():
    ...     print("Something")
    ... 
    >>> Process(target=target).start()
    >>> Something
    
    >>> 
    

    If we look at the processes after this:

    enter image description here

    While if we read the exit status of the process (with Process.exitcode), this does not happen.

    Each Process instance launches a new process in the background, how and when this subprocess is terminated is OS-dependant. Every OS provides some mean of communication between processes. Child processes are usually not terminated if you kill the “parent” process.

    For example doing this:

    >>> from multiprocessing import Process
    >>> import time
    >>> def target():
    ...     while True:
    ...             time.sleep(0.5)
    ... 
    >>> L = [Process(target=target) for i in range(10)]
    >>> for p in L: p.start()
    ... 
    

    The main python process will have 10 children:

    enter image description here

    Now if we kill that process we obtain this:

    enter image description here
    Note how the child processes where inherited by init and are still running.

    But, as I said, this is OS specific. On some OSes killing the parent process will kill all child processes.

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

Sidebar

Related Questions

I'm trying to write a python script that does the following from within a
am reading out of a database with the following python script: cur.execute(SELECT * FROM
I have a python script that reads raw movie text files into an sqlite
I have a very basic python script that does HTTP connection. import socket def
what happens to my script in python that does not run through crontab every
I have a python daemon process that gets started via rc.local. This same script,
I have a Python script that needs to execute an external program, but for
My goal is to execute a python script (that executs some unittests) via a
Suppose I have a perl (or python) script that does something highly secretive; I'd
I'm attempting to construct and execute a csh script from python. The code I

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.