VirtualBox

Changeset 65196 in vbox for trunk


Ignore:
Timestamp:
Jan 9, 2017 11:07:28 AM (8 years ago)
Author:
vboxsync
Message:

common/utils.py,testboxscript,tdUnitTest1: Create separate windows (console) process groups for children so we can safely generate Ctrl-C signals without also committing suicide. (testdriver.base.spawn already did this)

Location:
trunk/src/VBox/ValidationKit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/common/utils.py

    r65007 r65196  
    435435    return None;
    436436
     437def processPopenSafe(*aPositionalArgs, **dKeywordArgs):
     438    """
     439    Wrapper for subprocess.Popen that's Ctrl-C safe on windows.
     440    """
     441    if getHostOs() == 'win':
     442        if dKeywordArgs.get('creationflags', 0) == 0:
     443            dKeywordArgs['creationflags'] = subprocess.CREATE_NEW_PROCESS_GROUP;
     444    return subprocess.Popen(*aPositionalArgs, **dKeywordArgs);
     445
    437446def processCall(*aPositionalArgs, **dKeywordArgs):
    438447    """
    439     Wrapper around subprocess.call to deal with its absense in older
     448    Wrapper around subprocess.call to deal with its absence in older
    440449    python versions.
    441450    Returns process exit code (see subprocess.poll).
     
    444453    assert dKeywordArgs.get('stderr') is None;
    445454    _processFixPythonInterpreter(aPositionalArgs, dKeywordArgs);
    446     oProcess = subprocess.Popen(*aPositionalArgs, **dKeywordArgs);
     455    oProcess = processPopenSafe(*aPositionalArgs, **dKeywordArgs);
    447456    return oProcess.wait();
    448457
     
    453462    """
    454463    _processFixPythonInterpreter(aPositionalArgs, dKeywordArgs);
    455     oProcess = subprocess.Popen(stdout=subprocess.PIPE, *aPositionalArgs, **dKeywordArgs);
     464    oProcess = processPopenSafe(stdout=subprocess.PIPE, *aPositionalArgs, **dKeywordArgs);
    456465
    457466    sOutput, _ = oProcess.communicate();
     
    541550def sudoProcessPopen(*aPositionalArgs, **dKeywordArgs):
    542551    """
    543     sudo (or similar) + subprocess.Popen.
     552    sudo (or similar) + processPopenSafe.
    544553    """
    545554    _processFixPythonInterpreter(aPositionalArgs, dKeywordArgs);
    546555    _sudoFixArguments(aPositionalArgs, dKeywordArgs);
    547     return subprocess.Popen(*aPositionalArgs, **dKeywordArgs);
     556    return processPopenSafe(*aPositionalArgs, **dKeywordArgs);
    548557
    549558
  • trunk/src/VBox/ValidationKit/testboxscript/testboxscript.py

    r62484 r65196  
    3333__version__ = "$Revision$"
    3434
    35 import subprocess
    36 import sys
    37 import os
    38 import time
     35import platform;
     36import subprocess;
     37import sys;
     38import os;
     39import time;
    3940
    4041
     
    4243# @remarks These will _never_ change
    4344# @{
    44 TBS_EXITCODE_FAILURE        = 1         # RTEXITCODE_FAILURE
    45 TBS_EXITCODE_SYNTAX         = 2         # RTEXITCODE_SYNTAX
    46 TBS_EXITCODE_NEED_UPGRADE   = 9
     45TBS_EXITCODE_FAILURE        = 1;        # RTEXITCODE_FAILURE
     46TBS_EXITCODE_SYNTAX         = 2;        # RTEXITCODE_SYNTAX
     47TBS_EXITCODE_NEED_UPGRADE   = 9;
    4748## @}
    4849
     
    5960        Init
    6061        """
    61         self.task = None
     62        self.oTask = None
    6263
    6364    def __del__(self):
     
    6566        Cleanup
    6667        """
    67         if self.task is not None:
     68        if self.oTask is not None:
    6869            print 'Wait for child task...'
    69             self.task.terminate()
    70             self.task.wait()
     70            self.oTask.terminate()
     71            self.oTask.wait()
    7172            print 'done. Exiting'
    72             self.task = None;
     73            self.oTask = None;
    7374
    7475    def run(self):
     
    107108        rcExit = TBS_EXITCODE_FAILURE;
    108109        while True:
    109             self.task = subprocess.Popen(asArgs, shell=False);
    110             rcExit = self.task.wait();
    111             self.task = None;
     110            self.oTask = subprocess.Popen(asArgs,
     111                                          shell = False,
     112                                          creationflags = (0 if platform.system() != 'Windows'
     113                                                           else subprocess.CREATE_NEW_PROCESS_GROUP)); # for Ctrl-C isolation
     114            rcExit = self.oTask.wait();
     115            self.oTask = None;
    112116            if rcExit == TBS_EXITCODE_SYNTAX:
    113117                break;
  • trunk/src/VBox/ValidationKit/testboxscript/testboxtasks.py

    r62484 r65196  
    423423        # Spawn child.
    424424        try:
    425             oChild = subprocess.Popen(asArgs,
    426                                       shell      = False,
    427                                       bufsize    = -1,
    428                                       stdout     = subprocess.PIPE,
    429                                       stderr     = subprocess.STDOUT,
    430                                       cwd        = self._oTestBoxScript.getPathSpill(),
    431                                       universal_newlines = True,
    432                                       close_fds  = (False if utils.getHostOs() == 'win' else True),
    433                                       preexec_fn = (None if utils.getHostOs() in ['win', 'os2']
    434                                                     else os.setsid)); # pylint: disable=E1101
     425            oChild = utils.processPopenSafe(asArgs,
     426                                            shell      = False,
     427                                            bufsize    = -1,
     428                                            stdout     = subprocess.PIPE,
     429                                            stderr     = subprocess.STDOUT,
     430                                            cwd        = self._oTestBoxScript.getPathSpill(),
     431                                            universal_newlines = True,
     432                                            close_fds  = (False if utils.getHostOs() == 'win' else True),
     433                                            preexec_fn = (None if utils.getHostOs() in ['win', 'os2']
     434                                                          else os.setsid)); # pylint: disable=E1101
    435435        except Exception, oXcpt:
    436436            self._log('Error creating child process %s: %s' % (asArgs, oXcpt));
  • trunk/src/VBox/ValidationKit/tests/unittests/tdUnitTest1.py

    r62484 r65196  
    633633                    oChild = utils.sudoProcessPopen(asArgs, stdin = oDevNull, stdout = sys.stdout, stderr = sys.stdout);
    634634                else:
    635                     oChild = subprocess.Popen(      asArgs, stdin = oDevNull, stdout = sys.stdout, stderr = sys.stdout);
     635                    oChild = utils.processPopenSafe(asArgs, stdin = oDevNull, stdout = sys.stdout, stderr = sys.stdout);
    636636            except:
    637637                if sName in [ 'tstAsmStructsRC',    # 32-bit, may fail to start on 64-bit linux. Just ignore.
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette