[issue35268] Windows asyncio reading continously stdin and stdout Stockfish

2018-11-19 Thread Steve Dower


Steve Dower  added the comment:

Are you awaiting those calls (and the write())? I can't tell at first glance 
whether you need to, but it seems like missing await there would cause your 
problem.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35268] Windows asyncio reading continously stdin and stdout Stockfish

2018-11-17 Thread Cezary Wagner

Cezary Wagner  added the comment:

It looks like StremReader.read() not work and StremReader.readline() in Windows 
or I am not understand documentation.

https://docs.python.org/3/library/asyncio-stream.html

coroutine read(n=-1)

Read up to n bytes. If n is not provided, or set to -1, read until EOF and 
return all read bytes.

If EOF was received and the internal buffer is empty, return an empty bytes 
object.



coroutine readline()

Read one line, where “line” is a sequence of bytes ending with \n.

If EOF is received and \n was not found, the method returns partially read 
data.

If EOF is received and the internal buffer is empty, return an empty bytes 
object.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35268] Windows asyncio reading continously stdin and stdout Stockfish

2018-11-17 Thread Cezary Wagner


New submission from Cezary Wagner :

I have some problems with asyncio on Windows - it block where it should go.
Documentation shows that it should work: 
https://docs.python.org/3/library/asyncio-stream.html -> StreamReader should 
return something.

See 1st example:

import asyncio

import sys


async def run_stockfish():
STOCKFISH_PATH = r'C:\root\chess\stockfish\stockfish 
9\stockfish_9_x64_bmi2.exe'

stockfish = await asyncio.subprocess.create_subprocess_exec(
STOCKFISH_PATH,
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE)

stockfish.stdin.write('uci'.encode())

while True:
# BUG? - blocks at this line - no output
line = await stockfish.stdout.read()
print(line)

await stockfish.wait()


if sys.platform == "win32":
asyncio.set_event_loop_policy(
asyncio.WindowsProactorEventLoopPolicy())

asyncio.run(run_stockfish(), debug=True)

1st output (nothing):
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit 
(AMD64)] on win32
runfile('C:/Users/Cezary 
Wagner/PycharmProjects/stockfish-proxy/sandbox/async_proxy/s01_async_stockfish.py',
 wdir='C:/Users/Cezary 
Wagner/PycharmProjects/stockfish-proxy/sandbox/async_proxy')

2nd example:

import asyncio

import sys


async def run_stockfish():
STOCKFISH_PATH = r'C:\root\chess\stockfish\stockfish 
9\stockfish_9_x64_bmi2.exe'

stockfish = await asyncio.subprocess.create_subprocess_exec(
STOCKFISH_PATH,
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE)

stockfish.stdin.write('uci'.encode())

while True:
# BUG? - blocks at this line
line = await stockfish.stdout.readline()
print(line)

await stockfish.wait()


if sys.platform == "win32":
asyncio.set_event_loop_policy(
asyncio.WindowsProactorEventLoopPolicy())

asyncio.run(run_stockfish(), debug=True)

2nd output is little better (first line is read):
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit 
(AMD64)] on win32
runfile('C:/Users/Cezary 
Wagner/PycharmProjects/stockfish-proxy/sandbox/async_proxy/s01_async_stockfish.py',
 wdir='C:/Users/Cezary 
Wagner/PycharmProjects/stockfish-proxy/sandbox/async_proxy')
b'Stockfish 9 64 BMI2 by T. Romstad, M. Costalba, J. Kiiski, G. Linscott\r\n'

What should be done in both case (or maybe done):
Stockfish 9 64 BMI2 by T. Romstad, M. Costalba, J. Kiiski, G. Linscott
uci
id name Stockfish 9 64 BMI2
id author T. Romstad, M. Costalba, J. Kiiski, G. Linscott

option name Debug Log File type string default
option name Contempt type spin default 20 min -100 max 100
option name Threads type spin default 1 min 1 max 512
option name Hash type spin default 16 min 1 max 131072
option name Clear Hash type button
option name Ponder type check default false
option name MultiPV type spin default 1 min 1 max 500
option name Skill Level type spin default 20 min 0 max 20
option name Move Overhead type spin default 30 min 0 max 5000
option name Minimum Thinking Time type spin default 20 min 0 max 5000
option name Slow Mover type spin default 89 min 10 max 1000
option name nodestime type spin default 0 min 0 max 1
option name UCI_Chess960 type check default false
option name SyzygyPath type string default 
option name SyzygyProbeDepth type spin default 1 min 1 max 100
option name Syzygy50MoveRule type check default true
option name SyzygyProbeLimit type spin default 6 min 0 max 6
uciok

--
components: Windows, asyncio
messages: 330028
nosy: Cezary.Wagner, asvetlov, paul.moore, steve.dower, tim.golden, yselivanov, 
zach.ware
priority: normal
severity: normal
status: open
title: Windows asyncio reading continously stdin and stdout Stockfish
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com