Skip to content

Commit

Permalink
Add debugging, stop hang in ProcessInThread.
Browse files Browse the repository at this point in the history
  • Loading branch information
nwp90 committed May 26, 2016
1 parent eb0047c commit 80a45e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 4 additions & 0 deletions mdk/commands/behat.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,13 @@ def run(self, args):

# Kill the remaining processes
if phpServer and phpServer.is_alive():
logging.debug('Killing phpServer...')
phpServer.kill()
logging.debug('phpServer killed.')
if seleniumServer and seleniumServer.is_alive():
logging.debug('Killing seleniumServer...')
seleniumServer.kill()
logging.debug('seleniumServer killed.')

# Disable Behat
if args.disable:
Expand Down
22 changes: 14 additions & 8 deletions mdk/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import logging
import hashlib
import tempfile
import errno
from .config import Conf

C = Conf()
Expand Down Expand Up @@ -177,10 +178,13 @@ def process(cmd, cwd=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE):
logging.debug(' '.join(cmd))
try:
proc = subprocess.Popen(cmd, cwd=cwd, stdout=stdout, stderr=stderr)
logging.debug("subprocess started")
(out, err) = proc.communicate()
logging.debug("communicate done")
except KeyboardInterrupt as e:
proc.kill()
raise e
logging.debug("process returning")
return (proc.returncode, out, err)


Expand Down Expand Up @@ -235,16 +239,18 @@ def __init__(self, cmd, cwd=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE
self.stderr = stderr

def kill(self):
os.kill(self._pid, signal.SIGKILL)
try:
os.kill(self._pid, signal.SIGKILL)
except OSError as e:
if e.errno == errno.ESRCH:
logging.debug("ProcessInThread subprocess died before we could kill it")

def run(self):
logging.debug(' '.join(self.cmd))
proc = subprocess.Popen(self.cmd, cwd=self.cwd, stdout=self.stdout, stderr=self.stderr)
self._pid = proc.pid
while True:
if proc.poll():
break

# Reading the output seems to prevent the process to hang.
if self.stdout == subprocess.PIPE:
proc.stdout.read(1)
logging.debug("ProcessInThread subprocess started, pid %s", self._pid)
(out, err) = proc.communicate()
if err:
logging.debug(err)
logging.debug("ProcessInThread subprocess terminated with returncode %s", proc.returncode)

0 comments on commit 80a45e0

Please sign in to comment.