Created
June 7, 2014 01:01
-
-
Save takluyver/aef3bd23725aa34af7a3 to your computer and use it in GitHub Desktop.
Pexpect asyncio integration attempt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import pexpect | |
from pexpect.async import expect_async | |
p = pexpect.spawn('python') | |
p.setecho(False) | |
p.waitnoecho() | |
b = pexpect.spawn('bash') | |
b.setecho(False) | |
b.waitnoecho() | |
p.expect_exact('>>> ') | |
b.expect_exact("$ ") | |
p.sendline("import time; time.sleep(4); print('done')") | |
b.sendline("sleep 2 && echo 'done'") | |
@asyncio.coroutine | |
def wait_python(): | |
yield from expect_async(p, 'done') | |
print("Python done") | |
@asyncio.coroutine | |
def wait_bash(): | |
yield from expect_async(b, 'done') | |
print("Bash done") | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(asyncio.gather(wait_python(), wait_bash())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment