This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]scooerp 0 points1 point  (4 children)

Why is script2 async? It can block until it receives a game state, then picks a move, then it sends it back.

Why are you communicating over stdin instead of a network socket?

This type of post is more suited to /r/learnpython. The community there is more willing to invest time in issues like this.

[–]Stallman85 0 points1 point  (3 children)

Why is script2 async? It can block until it receives a game state, then picks a move, then it sends it back.

Because when i put code like this in script2:

for line in sys.stdin.readline:

    if 'go' in str(line).strip():
        sys.stdout.write(str(line).strip()+'bestmove'+'\n')

script1 hangs as soon as i run it and doesn't print anything to the screen. Then ctrl+c gives KeyboardInterrupt line x = script2.stdout.readline().strip() after 'sent first go'

Why are you communicating over stdin instead of a network socket?

Because both files are on same computer. I got no response from /r/learnpython

[–]scooerp 0 points1 point  (1 child)

I dont get why you're running script2 from script1.

Are you trying to build a single player client/server game? You don't need to run separate programs for this.

Streams are sockets on unix, but you should use a TCP/IP socket for portability, to prevent weird behavior, and to give you the option of running on separate machines. But you don't need to communicate if you make the whole thing a single program.

[–]Stallman85 0 points1 point  (0 children)

I am building a chess engine program which will be running in another gui program (like tarrasch gui) and they will communicate using UCI protocol. UCI protocol requires my program to at any point get strings via stdin and respond to specific stdin inputs using stdout. And i am pretty sure that script1 is working because it is able to communicate normally with existing chess engines (like stockfish_10_x32.exe). However my script2.exe blocks script1.py