import os import sys import json from time import sleep # if we open the fd before bun has written to it # we'll get a "bad fd" error :\ sleep(1) fd = 3 read_pipe = os.fdopen(fd, "r") write_pipe = os.fdopen(fd, "w") def read(): line = read_pipe.readline() print("[py]: bun -> py -> @raw", line.encode()) # TMP: fix bun bug - @see https://github.com/oven-sh/bun/issues/13799 if len(line) > 0 and line[0] == "\x01": line = line[1:] line = line.strip() if not line: sys.exit(0) msg = json.loads(line) print("[py]: bun -> py -> @json", msg) return msg def write(msg): print("[py]: py -> bun", msg) write_pipe.write(json.dumps(msg) + "\n") write_pipe.flush() while True: try: msg = read() write("msg recvd") except EOFError: break