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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:18:09+00:00 2026-06-11T19:18:09+00:00

Problem: I expect child to time out and be done. but instead it times

  • 0

Problem: I expect child to time out and be done. but instead it times out and begins to run again.

Can anyone tell me why this program runs forever? I expect it to run one time and exit…

Here is a working program. Master threads a function to spawn a child. Works great except it ends up looping.

Here is the master:

# master.py
import multiprocessing, subprocess, sys, time

def f():
    p = subprocess.Popen(["C:\\Python32\\python.exe", "child.py"])
    # wait until child ends and check exit code
    while p.poll() == None:
        time.sleep(2)
    if p.poll() != 0:
        print("something went wrong with child.py")

# multithread a function process to launch and monitor a child
p1 = multiprocessing.Process(target = f())
p1.start()

and the child:

# child.py
import socket, sys

def main(args):
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.settimeout(10)
        sock.bind(('', 54324))
        data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
        print(data)
        sock.close()
        return 0
    except KeyboardInterrupt as e:
        try:
            sock.close()
            return 0
        except:
            return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv))
  • 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-11T19:18:10+00:00Added an answer on June 11, 2026 at 7:18 pm

    The problem is that your master.py doesn’t have an if __name__ == '__main__' guard. On Windows, multiprocessing has to be able to reimport the main module in the child process, and if you don’t use this if guard, you will re-execute the multiprocessing.Process in the child (resulting in an accidental forkbomb).

    To fix, simply put all of the commands in master.py in the if guard:

    if __name__ == '__main__':
        # multithread a function process to launch and monitor a child
        p1 = multiprocessing.Process(target = f())
        p1.start()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: Only doGet gets called when I expect doPost to be called. I have
Here's an interesting problem to solve in minimal amounts of code. I expect the
(This is an Android SDK tools v17 problem. Expect a fix in v18) I
I've got stuck with a serialization problem. My Silverlight app doesn't expect one of
Having a weird problem sprintf(tmp, \%s\, filename); I expect the output to be filename
In summary, I am having a problem where I read what I expect to
i have very serious problem if any tech expert can help...thank you in advance..
I need to have my XSLT stylesheet sort my XML file's child nodes, but
Note: this is with SQLite, although I expect the problem is on the Qt
I'm writing a c# program that will launch many child processes. At some time

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.