from os import mkfifo, remove from os.path import exists class Pipe: def __init__(self, path): self.path = path def recreate(self): self.remove() self.create() def remove(self): if exists(self.path): remove(self.path) def create(self): mkfifo(self.path) def write(self, data): with open(self.path, 'wb') as pipe: pipe.write(data) def read(self): with open(self.path, 'rb') as pipe: return pipe.read()