Skip to content

Instantly share code, notes, and snippets.

@almet almet/named.py
Last active Jun 18, 2016

Embed
What would you like to do?
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
@davidbgk

This comment has been minimized.

Copy link

commented Jun 18, 2016

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.