Skip to content

Commit 4c6b243

Browse files
talking to a subprocess
1 parent 281eb05 commit 4c6b243

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

bpython/curtsies.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import sys
44
import code
55
import logging
6+
import select
7+
from subprocess import Popen, PIPE
68
from optparse import Option
79
from itertools import izip
810

@@ -71,6 +73,8 @@ def mainloop(config, locals_, banner, interp=None, paste=None, interactive=True)
7173
hide_cursor=False,
7274
extra_bytes_callback=input_generator.unget_bytes) as window:
7375

76+
p = Popen(['python', '-m', 'bpython.curtsiesfrontend.beeper'], stdout=PIPE)
77+
7478
refresh_requests = []
7579
def request_refresh():
7680
refresh_requests.append(curtsies.events.RefreshRequestEvent())
@@ -79,7 +83,18 @@ def event_or_refresh(timeout=None):
7983
if refresh_requests:
8084
yield refresh_requests.pop()
8185
else:
82-
yield input_generator.send(timeout)
86+
try:
87+
rs, ws, es = select.select([input_generator, p.stdout], [], [])
88+
except select.error as e:
89+
print e
90+
yield curtsies.events.SigIntEvent()
91+
else:
92+
for r in rs:
93+
if r is input_generator:
94+
yield input_generator.send(timeout)
95+
else:
96+
p.stdout.readline()
97+
yield u'a'
8398

8499
global repl # global for easy introspection `from bpython.curtsies import repl`
85100
with Repl(config=config,

bpython/curtsiesfrontend/beeper.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import time
2+
import sys
3+
4+
if __name__ == '__main__':
5+
while True:
6+
sys.stdout.write('beep\n')
7+
sys.stdout.flush()
8+
time.sleep(5)
9+

0 commit comments

Comments
 (0)