Ejemplo n.º 1
0
        public static bool TerminateProcess(
            PythonSubprocessHandle handle,
            object uExitCode)
        {
            // Alternative Managed API: System.Diagnostics.Process.Kill()
            IntPtr hProcessIntPtr = new IntPtr(Converter.ConvertToInt32(handle));
            uint   uExitCodeUint  = Converter.ConvertToUInt32(uExitCode);
            bool   result         = TerminateProcessPI(
                hProcessIntPtr,
                uExitCodeUint);

            return(result);
        }
Ejemplo n.º 2
0
        public static int GetExitCodeProcess(PythonSubprocessHandle hProcess)
        {
            if (hProcess._isProcess && hProcess._closed)
            {
                // deal with finalization & resurrection oddness...  see PythonSubprocessHandle finalizer
                return(hProcess._exitCode);
            }

            IntPtr hProcessIntPtr = new IntPtr(Converter.ConvertToInt32(hProcess));
            int    exitCode       = int.MinValue;

            GetExitCodeProcessPI(hProcessIntPtr, out exitCode);
            return(exitCode);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Duplicates a subprocess handle which was created for piping.
        ///
        /// This is only called when we're duplicating the handle to make it inheritable to the child process.  In CPython
        /// the parent handle is always reliably garbage collected.  Because we know this handle is not going to be
        /// used we close the handle being duplicated.
        /// </summary>
        public static PythonSubprocessHandle DuplicateHandle(CodeContext context,
                                                             BigInteger sourceProcess,
                                                             PythonSubprocessHandle handle,
                                                             BigInteger targetProcess,
                                                             int desiredAccess,
                                                             bool inherit_handle,
                                                             object DUPLICATE_SAME_ACCESS)
        {
            if (handle._duplicated)
            {
                // more ref counting issues - when stderr is set to subprocess.STDOUT we can't close the target handle so we need
                // to track this situation.
                return(DuplicateHandle(context, sourceProcess, (BigInteger)handle, targetProcess, desiredAccess, inherit_handle, DUPLICATE_SAME_ACCESS));
            }

            var res = DuplicateHandle(context, sourceProcess, (BigInteger)handle, targetProcess, desiredAccess, inherit_handle, DUPLICATE_SAME_ACCESS);

            res._duplicated = true;
            handle.Close();
            return(res);
        }
Ejemplo n.º 4
0
 public static int WaitForSingleObject(PythonSubprocessHandle handle, int dwMilliseconds)
 {
     return(WaitForSingleObjectPI(handle, dwMilliseconds));
 }
Ejemplo n.º 5
0
 public static void CloseHandle(PythonSubprocessHandle handle)
 {
     handle.Close();
 }
Ejemplo n.º 6
0
 public static int WaitForSingleObject(PythonSubprocessHandle handle, int dwMilliseconds) {
     return WaitForSingleObjectPI(handle, dwMilliseconds);
 }
Ejemplo n.º 7
0
        public static bool TerminateProcess(
            PythonSubprocessHandle handle,
            object uExitCode) {

            // Alternative Managed API: System.Diagnostics.Process.Kill()
            IntPtr hProcessIntPtr = new IntPtr(Converter.ConvertToInt32(handle));
            uint uExitCodeUint = Converter.ConvertToUInt32(uExitCode);
            bool result = TerminateProcessPI(
                hProcessIntPtr,
                uExitCodeUint);

            return result;
        }
Ejemplo n.º 8
0
        public static int GetExitCodeProcess(PythonSubprocessHandle hProcess) {
            if (hProcess._isProcess && hProcess._closed) {
                // deal with finalization & resurrection oddness...  see PythonSubprocessHandle finalizer
                return hProcess._exitCode;
            }

            IntPtr hProcessIntPtr = new IntPtr(Converter.ConvertToInt32(hProcess));
            int exitCode = int.MinValue;
            GetExitCodeProcessPI(hProcessIntPtr, out exitCode);
            return exitCode;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Duplicates a subprocess handle which was created for piping.
        /// 
        /// This is only called when we're duplicating the handle to make it inheritable to the child process.  In CPython
        /// the parent handle is always reliably garbage collected.  Because we know this handle is not going to be 
        /// used we close the handle being duplicated.
        /// </summary>
        public static PythonSubprocessHandle DuplicateHandle(CodeContext context,
            BigInteger sourceProcess,
            PythonSubprocessHandle handle,
            BigInteger targetProcess,
            int desiredAccess,
            bool inherit_handle,
            object DUPLICATE_SAME_ACCESS) {

            if (handle._duplicated) {
                // more ref counting issues - when stderr is set to subprocess.STDOUT we can't close the target handle so we need
                // to track this situation.
                return DuplicateHandle(context, sourceProcess, (BigInteger)handle, targetProcess, desiredAccess, inherit_handle, DUPLICATE_SAME_ACCESS);
            }

            var res = DuplicateHandle(context, sourceProcess, (BigInteger)handle, targetProcess, desiredAccess, inherit_handle, DUPLICATE_SAME_ACCESS);
            res._duplicated = true;
            handle.Close();
            return res;
        }