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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:25:19+00:00 2026-05-27T22:25:19+00:00

From within my python script, I want to start another python script which will

  • 0

From within my python script, I want to start another python script which will run in the background waiting for the instruction to terminate.

  1. Host Python script (H1) starts subprocess P1.
  2. P1 performs some short lived work & returns a sentinel to indicate that it is now going to sleep awaiting instructions to terminate.
  3. H1 polls for this sentinel repeatedly. When it receives the sentinel, it performs some other IO bound task and when that completes, tells P1 to die gracefully (meaning close any resources that you have acquired).

Is this feasible to do with the subprocess module ?

  • 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-27T22:25:20+00:00Added an answer on May 27, 2026 at 10:25 pm
    """H1"""
    from multiprocessing import Process, Pipe
    import sys
    
    def P1(conn):
        print 'P1: some short lived work'
        sys.stdout.flush()
        conn.send('work done')
        # wait for shutdown command...
        conn.recv()
        conn.close()
        print 'P1: shutting down'
    
    if __name__ == '__main__':
        parent_conn, child_conn = Pipe()
        p = Process(target=P1, args=(child_conn,))
        p.start()
        print parent_conn.recv()
        print 'H1: some other IO bound task'
        parent_conn.send("game over")
        p.join()
    

    Output:

    P1: some short lived work
    work done
    H1: some other IO bound task
    P1: shutting down
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to run a python script from within another. By within I mean
I want to run a command line program from within a python script and
How to run an AppleScript from within a Python script? The questions says it
I'm looking to call a python function from within another python script in a
From within a python script (main.py), I am using the subprocess module to run
How do I find out the current runtime directory from within a Python script?
I would like to call a Python script from within a Bash while loop.
From within my Java program I want to determine which .NET Framework is installed
I'm trying to write a python script that does the following from within a
Let's say you want to start a python script with some parameters like python

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.