install.fairie/dotfiles/.vim/plugged/ale/test/script/dumb_named_pipe_server.py
Git E2E Dev Test Username e149692cc9 git subrepo clone https://github.com/dense-analysis/ale.git ./dotfiles/.vim/plugged/ale
subrepo:
  subdir:   "dotfiles/.vim/plugged/ale"
  merged:   "e4b205440"
upstream:
  origin:   "https://github.com/dense-analysis/ale.git"
  branch:   "master"
  commit:   "e4b205440"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"
2022-10-18 10:37:09 -04:00

42 lines
941 B
Python

"""
This Python script creates a named pipe server that does nothing but send its input
back to the client that connects to it. Only one argument must be given, the path
of a named pipe to bind to.
"""
import os
import socket
import sys
def main():
if len(sys.argv) < 2:
sys.exit('You must specify a filepath')
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if os.path.exists(sys.argv[1]):
os.remove(sys.argv[1])
sock.bind(sys.argv[1])
sock.listen(0)
pid = os.fork()
if pid:
print(pid)
sys.exit()
while True:
connection = sock.accept()[0]
connection.settimeout(5)
while True:
try:
connection.send(connection.recv(1024))
except socket.timeout:
break
connection.close()
if __name__ == "__main__":
main()