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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:23:20+00:00 2026-06-08T20:23:20+00:00

On some machine, for the following piece of code p = subprocess.Popen(cmd, stdout =

  • 0

On some machine, for the following piece of code

p = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT);
out, err = p.communicate()

This script would just hang at p.communicate() and does not return.

After I manually run the command, I finally see the error messages.

Why is this, and how should I solve it?

Thanks.

  • 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-08T20:23:21+00:00Added an answer on June 8, 2026 at 8:23 pm

    I guess your program never ends?

    when you call communicate() it does different things under different os. But it always waits for the launched process to exit on its own eg. calls p.wait().
    p.wait() terminates only if the rocess terminates.

    Solutions:

    • You could copy the source code of subprocess.Popen._communicate and alter it so it does not use wait() but time.sleep and some timeout
    • You write your own code that reads stdout and stderr and stops if the program outputs too much stderr
    • You change the main() function of the file that never ands this way

    way

    def main():
        ## here is you program code
    
    if __name__ == '__main__':
        import thread, sys, time
        _id = thread.start_new(main, ())
        time.sleep(1)
        t = time.time() + 100 # execute maximum 100 + 1 seconds
        while t > time.time() and _id in sys._current_frames():
            time.sleep(0.001)
    

    If you want to look at the source of subprocess you can find it at subprocess.__file__.

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

Sidebar

Related Questions

For some reason, a simple piece of decorator-code fails on my production machine, but
I'm running into some strange machine/OS dependent GZipStream behavior in .NET 4.0. This is
[Edited: After cross-testing on a fresh machine and some additional research, this appears to
Working on some code for a machine problem; we've just started working with pointers,
I am developing some application in Linux .This Linux is a virtual machine running
The following piece of code was given to us from our instructor so we
I'm trying input validation in the following piece of code: typedef unsigned long DATATYPE;
When I run some code on my machine then it behaves as I expect
i have the following piece of code my my web.config: <customErrors mode=On defaultRedirect=~/Exception.aspx enableVersionHeader=false>
I am writing some Machine Learning code in MATLAB, and I am representing a

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.