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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:18:49+00:00 2026-06-09T00:18:49+00:00

this is the idea. I’ll have ‘main’ python script that will start (using subprocess)

  • 0

this is the idea. I’ll have ‘main’ python script that will start (using subprocess) app1 and app2. ‘main’ script will send input to app1 and output result to app2 and vice versa (and main script will need to remember what was sent so I can’t send pipe from app1 to app2).

This is main script.

import subprocess
import time

def main():
    prvi = subprocess.Popen(['python', 'random1.py'], stdin = subprocess.PIPE , stdout = subprocess.PIPE, stderr = subprocess.STDOUT)

    while 1:
        prvi.stdin.write('131231\n')
        time.sleep(1) # maybe it needs to wait
        print "procitano", prvi.stdout.read()

if __name__ == '__main__':
    main()

And this is ‘random1.py’ file.

import random

def main():
    while 1:
        inp = raw_input()
        print inp, random.random()
if __name__ == '__main__':
    main()

First I’ve tried with only one subprocess just to see if it’s working. And it’s not. It only outputs ‘procitano’ and waits there.
How can I read output from ‘prvi’ (without communicate(). When I use it, it exits my app and that’s something that I don’t want)?

  • 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-09T00:18:51+00:00Added an answer on June 9, 2026 at 12:18 am

    Add prvi.stdin.flush() after prvi.stdin.write(...).

    Explanation: To optimize communication between processes, the OS will buffer 4KB of data before it sends that whole buffer to the other process. If you send less data, you need to tell the OS “That’s it. Send it now” -> flush()

    [EDIT] The next problem is that prvi.stdout.read() will never return since the child doesn’t exit.

    You will need to develop a protocol between the processes, so each knows how many bytes of data to read when it gets something. A simple solution is to use a line based protocol (each “message” is terminated by a new line). To do that, replace read() with readline() and don’t forget to append \n to everything you send + flush()

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

Sidebar

Related Questions

I have this idea that using SQL VIEWS to abstract simple database computations (such
So I have this idea for a very simple service that will provide an
So I have this idea for a RubyGem that I think would be an
I have a html like this: The idea is that divs are floated left
So I have this idea that I've had since I started programming. I wanted
I have this idea: when someone calls mysite.com/layer1/layer2/something , then I want to start
I have this idea for a small-medium web application that I would like to
I have this idea that I should switch over from cmd.exe to powershell. It's
I had this idea... let's say I have a DIV that contains some text.
I have this idea to unify 10 systems, they will all share the same

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.