megalodon-chess / megalodon

Chess engine with the UCI protocol
https://megalodon-chess.github.io/megalodon/
GNU General Public License v3.0
14 stars 0 forks source link

Process Communication #11

Closed phuang1024 closed 3 years ago

phuang1024 commented 3 years ago

Describe changes

Use subprocess.Popen.stdin/stdout instead of opening files:

# OLD:
with open(IN, "r") as stdin, open(OUT, "w") as stdout:
    subprocess.Popen([path], stdin=stdin, stdout=stdout).wait()
# NEW:
p = subprocess.Popen([path], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
p.stdin.write(b"isready\n")
p.stdin.flush()
p.stdout.read()

Additional info

Changed and tested all three files in tests/.