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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:24:38+00:00 2026-06-06T19:24:38+00:00

Questions about Python’s subprocess.Popen() objects (Please assume a scenario where the number of bytes

  • 0

Questions about Python’s subprocess.Popen() objects
(Please assume a scenario where the number of bytes being generated for stdout/stderr does not fill up the OS pipe buffers and create a deadlock waiting for the OS pipe buffers to accept more data)

1) Does it matter what order p.stdout.read() and p.wait() are in?

2) Does read() on a stdout/stderr subprocess.PIPE block until the process has terminated?

3) Are the stdout/stderr subprocess.PIPE file objects and data available even after the process has terminated?

import subprocess
process = subprocess.Popen(args="ls", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout = process.stdout.read()
# Does the above read() block until the process has terminated?
stderr = process.stderr.read()
return_code = process.wait()

process = subprocess.Popen(args="ls", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
return_code = process.wait() 
# Are stdout and stderr pipes available now, even after the process terminated?
stdout = process.stdout.read()
stderr = process.stderr.read()
  • 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-06T19:24:39+00:00Added an answer on June 6, 2026 at 7:24 pm

    Q: Does it matter what order p.stdout.read() and p.wait() are in?
    A: No.

    Q: Does read() on a stdout/stderr subprocess.PIPE block until the process has terminated?
    A: If no limit on the number of bytes to read is specified, then it will block until the stream is closed (which is likely when the process terminates).

    Q: Are the stdout/stderr subprocess.PIPE file objects and data available even after the process has terminated?
    A: Yes.

    You may want to pay special attention to this warning from the subprocess documentation:

    Warning: This will deadlock when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. Use communicate() to avoid that.

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

Sidebar

Related Questions

I have 2 simple questions about python: 1.How to get number of lines of
There are a number of questions about how to parse a URL in Python,
I have some questions about the performance of this simple python script: import sys,
There are alot of questions on stackoverflow about installing mysql-python in virtualenv. However there
After one of my last questions about python&c++ integration i was told to use
I have the following questions about tweepy python module 1.I am trying to retrieve
there are lots of questions about split in python, but I couldn't find corresponding
I have questions about egg files in Python. I have much Python code organized
I was reading some questions about not to use exec or eval in python
I have two questions about creating thread safe types in python, and one related

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.