This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Cezary.Wagner
Recipients Cezary.Wagner, asvetlov, paul.moore, steve.dower, tim.golden, yselivanov, zach.ware
Date 2018-12-15.11:12:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1544872357.08.0.788709270274.issue35268@psf.upfronthosting.co.za>
In-reply-to
Content
Another code try - this time I am using task:

import asyncio

import sys


async def process_line_reader(process, on_line=None, on_eof=None):
    while not process.stdout.at_eof():
        # BUG? after first line it becomes dead
        line = await process.stdout.readline()
        if on_line is not None:
            on_line(line.decode())
    if on_eof is not None:
        on_eof()
        print('eof')


async def run_stockfish():
    STOCKFISH_PATH = r'C:\root\chess\stockfish\stockfish 10\stockfish_10_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())

    task = asyncio.create_task(process_line_reader(
        process=stockfish, on_line=lambda line: print(f'{line}')
    ))

    # await task

    await stockfish.wait()


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

asyncio.run(run_stockfish(), debug=True)
print('done')


All is blocked after first line (no print of eof or done):
C:\root\Python37-64\python.exe "C:/Users/Cezary Wagner/PycharmProjects/cw_chess_uci/sandbox/async_proxy/s02_async_stockfish.py"
Stockfish 10 64 BMI2 by T. Romstad, M. Costalba, J. Kiiski, G. Linscott
History
Date User Action Args
2018-12-15 11:12:37Cezary.Wagnersetrecipients: + Cezary.Wagner, paul.moore, tim.golden, asvetlov, zach.ware, yselivanov, steve.dower
2018-12-15 11:12:37Cezary.Wagnersetmessageid: <1544872357.08.0.788709270274.issue35268@psf.upfronthosting.co.za>
2018-12-15 11:12:37Cezary.Wagnerlinkissue35268 messages
2018-12-15 11:12:36Cezary.Wagnercreate