Код: Выделить всё
child.py
from random import randint
x = 1
while x < 9:
x = randint(0, 10)
print("weeeee got", x)
name = input("what's your name?\n")
print("hello", name)
x = 0
while True:
x += 1
print("bad", x)
Код: Выделить всё
parent.py
import curio
from curio import subprocess
async def main():
p = subprocess.Popen(
["./out"],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
)
async for line in p.stdout:
line = line.decode("ascii")
print(p.pid, "got:", line, end="")
if "what" in line and "name" in line:
out, _ = await p.communicate(input=b"yaboi\n")
print(p.pid, "got:", out.decode("ascii"), end="")
# stuff to properly kill the process ...
return
if __name__ == "__main__:
curio.run(main)
Код: Выделить всё
out, _ = await p.communicate(input=b"yaboi\n")
Код: Выделить всё
x = 1
while x < 9:
x = randint(0, 10)
print("weeeee got", x)
Подробнее здесь: https://stackoverflow.com/questions/790 ... inite-loop