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

  • Home
  • SEARCH
  • 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 6145555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:48:36+00:00 2026-05-23T18:48:36+00:00

After spawning a subprocess using the Python subprocess library, I’m using stderr to pass

  • 0

After spawning a subprocess using the Python subprocess library, I’m using stderr to pass a message from the child process to the parent process containing some serialized data. I then want the parent to return (via stdin) the result of a function applied to this data.

In essence, I have a function inside the subprocess that does something like this:

sys.stderr.write("some stuff to write")
# some time later
some_var = sys.stdin.read()

However, this completes locks the parent while waiting for the stderr input, so I tried to call:

sys.stderr.flush()
os.fsync(sys.stderr.fileno())

However, this doesn’t work. Nothing after the os.fsync is executed. In addition, when I call proc.poll() in the parent process, it appears, the child’s return code is 1.

What can I do to prevent this? Should I consider another approach?

  • 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-23T18:48:37+00:00Added an answer on May 23, 2026 at 6:48 pm

    I would consider another approach.
    You may use an indipendent process (multiprocessing.Process) and using two queues to communicate with it (multiprocessing.Queue) one for the input and the other one for the output.
    Example on starting the process:

    import multiprocessing
    
    def processWorker(input, result):
        work = input.get()
        print work
        result.put(work*work)
    
    input  = multiprocessing.Queue()
    result = multiprocessing.Queue()
    
    p = multiprocessing.Process(target = processWorker, args = (input, result))
    p.start()
    
    input.put(2)
    res = result.get(block = True)
    print res
    

    Then you may iterate passing again it. Usage of multiprocessing.Queue is more robust since you do not need to rely on stdout/err parsing and you also avoid related limitation.
    Moreover you can easily manage more subprocesses.

    Then, you can also set a timeout on how long you want a get call to wait at max, eg:

    import queue
    try:
        res = result.get(block = True, timeout = 10)
    except Queue.Empty:
        print error
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After reading the Head First Design Patterns book and using a number of other
After the suggestion to use a library for my ajax needs I am going
Using a delegate I can call any function asynchronously. From the documentation I understand
I am writing a terminal emulator in ruby using the PTY library. /dev/tty0 is
After writing and reading an xml string to and from a stream, it ceases
I am using Python with psycopg2 and I'm trying to run a full VACUUM
I've having the opposite problem of many Python users--my program is using too little
I'd like to control a bash program from within Python. I'd like to run
After reading this question , I was reminded of when I was taught Java
After upgrading to the latest version of TortoiseSVN (1.5.2.13595), it's context menu is no

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.