Logo Search packages:      
Sourcecode: qm version File versions

def qm::executable::Executable::Spawn (   self,
  arguments = [],
  environment = None,
  dir = None,
  path = None,
  exception_pipe = None 
) [inherited]

Spawn the program.

'arguments' -- The sequence of arguments that should be passed
to the executable.  The first argument provided in this
sequence will be 'argv[0]'; that is also the value used for
the path to the executable.

'environment' -- If not 'None', a dictionary giving the
environment that should be provided to the child.

'dir' -- If not 'None', the directory in which the child
should begin execution.  If 'None', the child will execute in
the same directory as the parent.

'path' -- If not 'None', the path to the program to run.  If
'None', 'arguments[0]' is used.

'exception_pipe' -- If not 'None', a pipe that the child can
use to communicate an exception to the parent.  This pipe is
only used on UNIX systems.  The write end of the pipe will be
closed by this function.

returns -- The PID of the child.

Before creating the child, the parent will call
'self._InitializeParent'.  On UNIX systems, the child will
call 'self._InitializeChild' after 'fork', but before 'exec'.
On non-UNIX systems, 'self._InitializeChild' will never be
called.

After creating the child, 'self._HandleChild' is called in the
parent.  This hook should be used to handle tasks that must be
performed after the child is running.

If the path to the program is absolute, or contains no
separator characters, it is not modified.  Otherwise the path
to the program is relative, it is transformed into an absolute
path using 'dir' as the base, or the current directory if
'dir' is not set.

Definition at line 60 of file executable.py.

                                                 :
        """Spawn the program.

        'arguments' -- The sequence of arguments that should be passed
        to the executable.  The first argument provided in this
        sequence will be 'argv[0]'; that is also the value used for
        the path to the executable.

        'environment' -- If not 'None', a dictionary giving the
        environment that should be provided to the child.

        'dir' -- If not 'None', the directory in which the child
        should begin execution.  If 'None', the child will execute in
        the same directory as the parent.

        'path' -- If not 'None', the path to the program to run.  If
        'None', 'arguments[0]' is used.

        'exception_pipe' -- If not 'None', a pipe that the child can
        use to communicate an exception to the parent.  This pipe is
        only used on UNIX systems.  The write end of the pipe will be
        closed by this function.

        returns -- The PID of the child.

        Before creating the child, the parent will call
        'self._InitializeParent'.  On UNIX systems, the child will
        call 'self._InitializeChild' after 'fork', but before 'exec'.
        On non-UNIX systems, 'self._InitializeChild' will never be
        called.

        After creating the child, 'self._HandleChild' is called in the
        parent.  This hook should be used to handle tasks that must be
        performed after the child is running.

        If the path to the program is absolute, or contains no
        separator characters, it is not modified.  Otherwise the path
        to the program is relative, it is transformed into an absolute
        path using 'dir' as the base, or the current directory if
        'dir' is not set."""

        # Remember the directory in which the execution will occur.
        self.__dir = dir

        # The path to the executable is the first argument, if not
        # explicitly specified.
        if not path:
            path = arguments[0]

        # Normalize the path name.
        if os.path.isabs(path):
            # An absolute path.
            pass
        elif (os.sep in path or (os.altsep and os.altsep in path)):
            # A relative path name, like "./program".
            if dir:
                path = os.path.normpath(os.path.join(dir, path))
                if not os.path.isabs(path):
                    path = os.path.abspath(path)
            else:
                path = os.path.abspath(path)
        else:
            # A path with no directory separators.  The program to
            # execute will be found by searching the PATH environment
            # variable.
            pass

        # Initialize the parent.
        startupinfo = self._InitializeParent()

        if sys.platform == "win32":
            # Compute the command line.  The Windows API uses a single
            # string as the command line, rather than an array of
            # arguments.
            command_line = self.__CreateCommandLine(arguments)

            # Windows supports wide-characters in the environment, but
            # the Win32 extensions to Python require that all of the
            # entries in the environment be of the same type,
            # i.e,. that either all of them be of type StringType or
            # of type UnicodeType.  Therefore, if we find any elements
            # that are Unicode strings, convert all of them to Unicode
            # strings.
            if environment is not None:
                # See if there any Unicode strings in the environment.
                uses_unicode = 0
                for (k, v) in environment.iteritems():
                    if (isinstance(k, unicode)
                        or isinstance(v, unicode)):
                        uses_unicode = 1
                        break
                # If there are Unicode strings in the environment,
                # convert all of the key-value pairs to Unicode.
                if uses_unicode:
                    new_environment = {}
                    for (k, v) in environment.iteritems():
                        new_environment[unicode(k)] = unicode(v)
                    environment = new_environment
                        
            # Create the child process.
            self.__child \
                = win32process.CreateProcess(path,
                                             command_line,
                                             None,
                                             None,
                                             1,
                                             0,
                                             environment,
                                             self.__dir,
                                             startupinfo)[0]
        else:
            # Fork.
            self.__child = os.fork()

            if self.__child == 0:
                try:
                    # Close the read end of the pipe.
                    if exception_pipe:
                        os.close(exception_pipe[0])
                    # Initialize the child.
                    self._InitializeChild()
                    # Exec the program.
                    if environment:
                        os.execvpe(path, arguments, environment)
                    else:
                        os.execvp(path, arguments)
                except:
                    if exception_pipe:
                        # Get the exception information.
                        exc_info = sys.exc_info()
                        # Write it to the pipe.  The traceback object
                        # cannot be pickled, unfortunately, so we
                        # cannot communicate that information.
                        cPickle.dump(exc_info[:2],
                                     os.fdopen(exception_pipe[1], "w"),
                                     1)
                    # Exit without running cleanups.
                    os._exit(1)

                # This code should never be reached.
                assert None

        # Nothing will be written to the exception pipe in the parent.
        if exception_pipe:
            os.close(exception_pipe[1])
            
        # Let the parent take any actions required after creating the
        # child.
        self._HandleChild()
        
        return self.__child


    def Run(self, arguments=[], environment = None, dir = None,


Generated by  Doxygen 1.6.0   Back to index