Last active
September 24, 2016 09:42
-
-
Save zed/7378451 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""Emulate bash: | |
$ cat /tmp/fifo.tub & | |
$ gunzip -c /tmp/filedata.dat.gz > /tmp/fifo.tub | |
http://stackoverflow.com/questions/19859283/python-subprocess-hangs-with-named-pipes | |
""" | |
import os | |
from contextlib import contextmanager | |
from shutil import rmtree | |
from subprocess import Popen, check_call | |
from tempfile import mkdtemp | |
@contextmanager | |
def named_pipe(): | |
dirname = mkdtemp() | |
try: | |
path = os.path.join(dirname, 'named_pipe') | |
os.mkfifo(path) | |
yield path | |
finally: | |
rmtree(dirname) | |
with named_pipe() as path, Popen(["cat", path]), open(path, 'wb') as f: | |
check_call("gunzip -c /tmp/filedata.dat.gz".split(), stdout=f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment