Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debugging, stop hang in ProcessInThread. #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mdk/commands/behat.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,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, encoding='utf-8')
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.decode('utf-8') if type(out) == bytes else out, err)


Expand Down Expand Up @@ -244,16 +248,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)