Permalink
Browse files

fixed lockup on bash exit

  • Loading branch information...
1 parent dad874f commit c62913fd1b0c0c54d49ee725ff01e34afeb24d46 @wuub committed Feb 19, 2012
Showing with 7 additions and 5 deletions.
  1. +7 −5 process.py
View
@@ -116,13 +116,11 @@ def start(self):
self._start()
def _start(self):
- def preexec():
- os.setsid()
(self._master, self._slave) = pty.openpty()
#ttyname = os.ttyname(self._slave)
self._process = subprocess.Popen(self._cmd, stdin=self._slave,
stdout=self._slave, stderr=self._slave, shell=False,
- env=self._env, close_fds=True, preexec_fn=preexec)
+ env=self._env, close_fds=True, preexec_fn=os.setsid)
def refresh_views(self):
sc = self._screens['diff']
@@ -135,11 +133,14 @@ def refresh_views(self):
def _read(self):
import select
+
read = 0
while True:
(r,w,x) = select.select([self._master], [], [], 0)
if not r:
break # no input
+ if not self.is_running():
+ return # dont lock on exit!
data = os.read(self._master, 1024)
read += len(data)
self._stream.feed(data)
@@ -148,15 +149,16 @@ def _read(self):
def send_bytes(self, bytes):
import os
- os.write(self._master, bytes)
+ if self.is_running():
+ os.write(self._master, bytes)
def stop(self):
self._process.kill()
self._process = None
return
def is_running(self):
- return self._process is not None
+ return self._process is not None and self._process.poll() is None
def send_ctrl(self, key):
char = key.lower()

0 comments on commit c62913f

Please sign in to comment.