Pipe stdin to a spawned process with subprocess module?

This is the place for queries that don't fit in any of the other categories.

Pipe stdin to a spawned process with subprocess module?

Postby soundeffects » Sun Aug 03, 2014 8:35 pm

I'm learning Python and using 2.7.6.

Is there an recommended way to pipe stdin from a string object to a spawned process using subprocess module? For pipes, the documentation recommends using the
Code: Select all
communicate(piped_input_string)
method of a Popen instance, and it even includes a warning to
Use communicate() rather than .stdin.write, .stdout.read or .stderr.read to avoid deadlocks due to any of the other OS pipe buffers filling up and blocking the child process.
But the communicate() waits for the process to finish, while I need the process to persist.

I recognize that one can write a subclass of Popen and override the communicate() method, replacing the call to wait() therein with a call to poll(). But that seems excessive, and I'm prone to introducing unforeseen errors.
Last edited by Yoriz on Sun Aug 03, 2014 10:51 pm, edited 1 time in total.
Reason: First post lock.
soundeffects
 
Posts: 1
Joined: Sun Aug 03, 2014 8:30 pm

Re: Pipe stdin to a spawned process with subprocess module?

Postby Yoriz » Sun Aug 03, 2014 10:51 pm

Welcome to the forum, Please read the new users read this link in my signature.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Image
User avatar
Yoriz
 
Posts: 1161
Joined: Fri Feb 08, 2013 1:35 am
Location: UK


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot], snippsat, W3C [Linkcheck] and 3 guests