Skip to content

Instantly share code, notes, and snippets.

@davidbgk
Forked from almet/named.py
Created June 18, 2016 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidbgk/7866f7aefa1da2a6067ed1cd7b284a81 to your computer and use it in GitHub Desktop.
Save davidbgk/7866f7aefa1da2a6067ed1cd7b284a81 to your computer and use it in GitHub Desktop.
Use named pipes to stream answers between processes without buffering (thanks to stdbuf -o0)
import os
import shlex
import subprocess
def spawn(cmd):
os.mkfifo("toto")
with open("toto", "w") as f:
process = subprocess.Popen(shlex.split(cmd), stdout=f)
process.wait()
os.unlink("toto")
spawn("stdbuf -o0 python test.py")
from __future__ import print_function
import os
import os.path
def read_fifo(filename):
with open(filename) as fifo:
while os.path.exists(filename):
print(fifo.readline(), end='')
read_fifo("toto")
#! /use/bin/python
import time
for i in range(100):
time.sleep(0.2)
print i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment