Bug 1139722 - Allow use of nested job objects in mozprocess on windows versions that support them.;r=ahal

This patch detects when breaking away from the parent job isn't strictly necessary to manage processses in a new job to allow using nested job objects to manage processes and their children. Loss of job object functionality is handled in mozprocess as non-fatal, however mozrunner and others doing things like restarting firefox require it.
This commit is contained in:
Chris Manchester 2015-03-05 18:02:38 -08:00
parent da5382b1ed
commit c24261f79e

View File

@ -211,11 +211,12 @@ class ProcessHandlerMixin(object):
comspec = os.environ.get("COMSPEC", "cmd.exe")
args = comspec + " /c " + args
# determine if we can create create a job
canCreateJob = winprocess.CanCreateJobObject()
# Determine if we can create a job or create nested jobs.
can_create_job = winprocess.CanCreateJobObject()
can_nest_jobs = self._can_nest_jobs()
# Ensure we write a warning message if we are falling back
if not canCreateJob and not self._ignore_children:
if not (can_create_job or can_nest_jobs) and not self._ignore_children:
# We can't create job objects AND the user wanted us to
# Warn the user about this.
print >> sys.stderr, "ProcessManager UNABLE to use job objects to manage child processes"
@ -223,9 +224,9 @@ class ProcessHandlerMixin(object):
# set process creation flags
creationflags |= winprocess.CREATE_SUSPENDED
creationflags |= winprocess.CREATE_UNICODE_ENVIRONMENT
if canCreateJob:
if can_create_job:
creationflags |= winprocess.CREATE_BREAKAWAY_FROM_JOB
else:
if not (can_create_job or can_nest_jobs):
# Since we've warned, we just log info here to inform you
# of the consequence of setting ignore_children = True
print "ProcessManager NOT managing child processes"
@ -244,7 +245,7 @@ class ProcessHandlerMixin(object):
self.pid = pid
self.tid = tid
if not self._ignore_children and canCreateJob:
if not self._ignore_children and (can_create_job or can_nest_jobs):
try:
# We create a new job for this process, so that we can kill
# the process and any sub-processes
@ -318,6 +319,17 @@ falling back to not using job objects for managing child processes"""
if i is not None:
i.Close()
def _can_nest_jobs(self):
# Per:
# https://msdn.microsoft.com/en-us/library/windows/desktop/hh448388%28v=vs.85%29.aspx
# Nesting jobs came in with windows versions starting with 6.2 according to the table
# on this page:
# https://msdn.microsoft.com/en-us/library/ms724834%28v=vs.85%29.aspx
winver = sys.getwindowsversion()
return (winver.major > 6 or
winver.major == 6 and winver.minor >= 2)
# Windows Process Manager - watches the IO Completion Port and
# keeps track of child processes
def _procmgr(self):