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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:42:51+00:00 2026-06-07T23:42:51+00:00

How can I feed data from one pipe to three different processes? nulfp =

  • 0

How can I feed data from one pipe to three different processes?

nulfp = open(os.devnull, "w")

piper = Popen([
    "come command",
    "some params"
], stdout = PIPE, stderr = nulfp.fileno())

pipe_consumer_1 = Popen([
    "come command",
    "some params"
], stdin = piper.stdout, stderr = nulfp.fileno())

pipe_consumer_2 = Popen([
    "come command",
    "some params"
], stdin = piper.stdout, stderr = nulfp.fileno())

pipe_consumer_3 = Popen([
    "come command",
    "some params"
], stdin = piper.stdout, stderr = nulfp.fileno())

pipe_consumer_1.communicate()
pipe_consumer_2.communicate()
pipe_consumer_3.communicate()
piper.communicate()

If I run the code above, it will produce a corrupted file. Meaning that pipe consumers are probably not reading the full output from the piper.

This one works properly but is much slower:

nulfp = open(os.devnull, "w")

piper_1 = Popen([
    "come command",
    "some params"
], stdout = PIPE, stderr = nulfp.fileno())

piper_2 = Popen([
    "come command",
    "some params"
], stdout = PIPE, stderr = nulfp.fileno())

piper_3 = Popen([
    "come command",
    "some params"
], stdout = PIPE, stderr = nulfp.fileno())

pipe_consumer_1 = Popen([
    "come command",
    "some params"
], stdin = piper_1.stdout, stderr = nulfp.fileno())

pipe_consumer_2 = Popen([
    "come command",
    "some params"
], stdin = piper_2.stdout, stderr = nulfp.fileno())

pipe_consumer_3 = Popen([
    "come command",
    "some params"
], stdin = piper_3.stdout, stderr = nulfp.fileno())

pipe_consumer_1.communicate()
pipe_consumer_2.communicate()
pipe_consumer_3.communicate()
piper_1.communicate()
piper_2.communicate()
piper_3.communicate()

Any suggestions how to make the first code snippet work the same way as the second one? If I get the first approach to work, the process would finish in 1/3 of time.

  • 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-07T23:42:53+00:00Added an answer on June 7, 2026 at 11:42 pm

    This only uses a single byte ‘block’ but you get the idea.

    from subprocess import Popen, PIPE
    
    cat_proc = '/usr/bin/cat'
    
    consumers = (Popen([cat_proc], stdin = PIPE, stdout = open('consumer1', 'w')),
                 Popen([cat_proc], stdin = PIPE, stdout = open('consumer2', 'w')),
                 Popen([cat_proc], stdin = PIPE, stdout = open('consumer3', 'w'))
    )
    
    
    with open('inputfile', 'r') as infile:
       for byte in infile:
           for consumer in consumers:
               consumer.stdin.write(byte)
    

    When testing, the consumer output files matches the input file.

    Edit:
    Here is reading from a process with 1K blocks.

    from subprocess import Popen, PIPE
    
    cat_proc = '/usr/bin/cat'
    
    consumers = (Popen([cat_proc], stdin = PIPE, stdout = open('consumer1', 'w')),
                 Popen([cat_proc], stdin = PIPE, stdout = open('consumer2', 'w')),
                 Popen([cat_proc], stdin = PIPE, stdout = open('consumer3', 'w'))
    )
    
    producer = Popen([cat_proc, 'inputfile'], stdout = PIPE)
    
    while True:
        byte = producer.stdout.read(1024)
        if not byte: break
        for consumer in consumers:
            consumer.stdin.write(byte)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two DB's one is feed by filtered data from another, now i'm
Can JavaScript load an RSS XML feed from Yahoo ? Is client-side JS allowed
I'm trying to scrape data from an external JSON feed and store it in
Some json from picasaweb: http://picasaweb.google.com/data/feed/api/user/100489095734859091829?kind=album&access=visible&alt=json-in-script&thumbsize=144c Here's the output as tidied up by jsonview -
Is there a class where one can create it by specifying the encoding, feed
Am trying to parse the RSS feed from www.ted.com/talks/rss, I can access all normal
I just started using SimpleXML to get a feed and display data from that
I use a JTable to display data sourced from a streaming data feed. Each
I'm working on a TableView which controller downloads data from a web feed, parse
Is there some kind of software that I can feed uploaded images to and

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.