From: ana Date: Tue, 13 Oct 2015 12:22:19 +0000 (+0300) Subject: Win32: remove obsolete win32pm implementation X-Git-Tag: V7_7_0rc1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=eb8bb67cf17a6cd12ef957ab2f60b98258af2279;p=modules%2Fkernel.git Win32: remove obsolete win32pm implementation --- diff --git a/bin/killSalomeWithPort.py b/bin/killSalomeWithPort.py index d973eae00..95497f0db 100755 --- a/bin/killSalomeWithPort.py +++ b/bin/killSalomeWithPort.py @@ -248,12 +248,11 @@ def __killMyPort(port, filedict): for l in lines: try: pidfield = l.split()[0] # pid should be at the first position + if verbose(): print 'stop process '+pidfield+' : omniNames' if sys.platform == "win32": - import win32pm #@UnresolvedImport - if verbose(): print 'stop process '+pidfield+' : omniNames' - win32pm.killpid(int(pidfield),0) + from salome_utils import win32killpid + win32killpid(int(pidfield)) else: - if verbose(): print 'stop process '+pidfield+' : omniNames' os.kill(int(pidfield),signal.SIGKILL) pass pass @@ -296,8 +295,8 @@ def __killMyPort(port, filedict): try: if sys.platform == "win32": - import win32pm #@UnresolvedImport @Reimport - win32pm.killpid(int(pid),0) + from salome_utils import win32killpid + win32killpid(int(pid)) else: os.kill(int(pid),signal.SIGKILL) pass @@ -433,8 +432,8 @@ def killMyPortSpy(pid, port): dt = 1.0 while 1: if sys.platform == "win32": - from win32pm import killpid #@UnresolvedImport - if killpid(int(pid), 0) != 0: + from salome_utils import win32killpid + if win32killpid(int(pid)) != 0: return else: from os import kill diff --git a/bin/runSalome.py b/bin/runSalome.py index 50310e9d6..22af40af1 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -99,11 +99,8 @@ class InterpServer(Server): global process_id command = self.CMD print "INTERPSERVER::command = ", command - if sys.platform == "win32": - import win32pm - pid = win32pm.spawnpid( string.join(command, " "),'-nc' ) - else: - pid = os.spawnvp(os.P_NOWAIT, command[0], command) + import subprocess + pid = subprocess.Popen(command).pid process_id[pid]=self.CMD self.PID = pid diff --git a/bin/salome_utils.py b/bin/salome_utils.py index 090332386..cf87ef39d 100644 --- a/bin/salome_utils.py +++ b/bin/salome_utils.py @@ -483,4 +483,17 @@ def setVerbose(level): global _verbose _verbose = level return + +# -- + +def win32killpid(pid): + """ + Kill process by pid on windows platform. + """ + if verbose(): print "######## win32killpid pid = ", pid + import ctypes + handle = ctypes.windll.kernel32.OpenProcess(1, False, pid) + ret = ctypes.windll.kernel32.TerminateProcess(handle, -1) + ctypes.windll.kernel32.CloseHandle(handle) + return ret # -- diff --git a/bin/server.py b/bin/server.py index dcb9488f4..fc36db0a4 100755 --- a/bin/server.py +++ b/bin/server.py @@ -69,8 +69,8 @@ class Server: command = myargs + self.CMD #print "command = ", command if sys.platform == "win32": - import win32pm - pid = win32pm.spawnpid( command, '-nc' ) + import subprocess + pid = subprocess.Popen(command).pid elif Server.server_launch_mode == "fork": pid = os.spawnvp(os.P_NOWAIT, command[0], command) else: # Server launch mode is daemon diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index 23ff57b31..0072c2443 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -1000,7 +1000,7 @@ void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream, SALOM void SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(std::string& command) { #ifdef WIN32 - command = "%PYTHONBIN% -c \"import win32pm ; win32pm.spawnpid(r'" + command + "', '')\""; + command = "%PYTHONBIN% -c \"import subprocess ; subprocess.Popen(command).pid\""; #else command += " &"; #endif diff --git a/src/win32pm/setup.py b/src/win32pm/setup.py deleted file mode 100755 index 483eb2f15..000000000 --- a/src/win32pm/setup.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: iso-8859-1 -*- -# Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# - -from distutils.core import setup, Extension - -module1 = Extension('win32pm', - libraries = ['kernel32'], - sources = ['win32pm.c']) - -setup (name = 'win32pm', - version = '1.0', - description = 'Win32 process managment package', - ext_modules = [module1]) diff --git a/src/win32pm/win32pm.c b/src/win32pm/win32pm.c deleted file mode 100755 index a740a4194..000000000 --- a/src/win32pm/win32pm.c +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include -#include - -static PyObject * win32pm_spawnhandle( PyObject *self, PyObject *args ) -{ - char *argv; - char *flags; - STARTUPINFO si; - PROCESS_INFORMATION pi; - DWORD dwProcessFlags = CREATE_NEW_CONSOLE; - /* Default value as in Python sources: - CREATE_NEW_CONSOLE has been known to - cause random failures on win9x. Specifically a - dialog: - "Your program accessed mem currently in use at xxx" - and a hopeful warning about the stability of your - system. - Cost is Ctrl+C wont kill children, but anyone - who cares can have a go! - */ - - if (!PyArg_ParseTuple(args, "s|s", &argv, &flags)) - return NULL; - if ( flags && !strcmp( flags, "-nc" ) ) // no console - dwProcessFlags = 0; - - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - if ( !CreateProcess( NULL, argv, - NULL, // Process handle not inheritable. - NULL, // Thread handle not inheritable. - TRUE, - dwProcessFlags, // Creation flags. - NULL, // Use parent's environment block. - NULL, // Use parent's starting directory. - &si, // Pointer to STARTUPINFO structure. - &pi ) ) // Pointer to PROCESS_INFORMATION structure. - return NULL; - return Py_BuildValue("i", pi.hProcess); -} - -static PyObject * win32pm_spawnpid( PyObject *self, PyObject *args ) -{ - char* argv; - char *flags; - STARTUPINFO si; - PROCESS_INFORMATION pi; - DWORD dwProcessFlags = CREATE_NEW_CONSOLE; - /* Default value as in Python sources: - CREATE_NEW_CONSOLE has been known to - cause random failures on win9x. Specifically a - dialog: - "Your program accessed mem currently in use at xxx" - and a hopeful warning about the stability of your - system. - Cost is Ctrl+C wont kill children, but anyone - who cares can have a go! - */ - - if (!PyArg_ParseTuple(args, "s|s", &argv, &flags)) - return NULL; - if ( flags && !strcmp( flags, "-nc" ) ) // no console - dwProcessFlags = 0; - - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - if ( !CreateProcess( NULL, argv, - NULL, // Process handle not inheritable. - NULL, // Thread handle not inheritable. - TRUE, - dwProcessFlags, // Creation flags. - NULL, // Use parent's environment block. - NULL, // Use parent's starting directory. - &si, // Pointer to STARTUPINFO structure. - &pi ) ) // Pointer to PROCESS_INFORMATION structure. - return NULL; - return Py_BuildValue("i", pi.dwProcessId); -} - -static PyObject * win32pm_handle( PyObject *self, PyObject *args ) -{ - int argv1 = 0; - int argv2 = 0; - HANDLE ph = 0; - int pid = 0; - if (!PyArg_ParseTuple(args, "i|i", &argv1, &argv2)) - return NULL; - ph = OpenProcess( 1, (BOOL)argv2, argv1 ); - return Py_BuildValue("i", (int)ph ); -} - -static PyObject * win32pm_killpid( PyObject *self, PyObject *args ) -{ - int pid = 0; - int exitCode = 0; - HANDLE ph = 0; - BOOL stat = 0; - if (!PyArg_ParseTuple(args, "i|i", &pid, &exitCode)) - return NULL; - ph = OpenProcess( 1, 0, pid ); - stat = TerminateProcess( ph, exitCode ); - return Py_BuildValue("i", (int)stat ); -} - -static PyObject * win32pm_killhandle( PyObject *self, PyObject *args ) -{ - int phId = 0; - int exitCode = 0; - BOOL stat = 0; - if (!PyArg_ParseTuple(args, "i|i", &phId, &exitCode)) - return NULL; - - stat = TerminateProcess( (void*)phId, exitCode ); - return Py_BuildValue("i", (int)stat ); -} - -static PyMethodDef win32pmMethods[] = { - {"spawnhandle", win32pm_spawnhandle, METH_VARARGS, - "Creates new process. Returns windows handle of new process."}, - {"spawnpid", win32pm_spawnpid, METH_VARARGS, - "Creates new process. Returns PID of new process."}, - {"handle", win32pm_handle, METH_VARARGS, - "Returns windows handle of indicated process PID."}, - {"killpid", win32pm_killpid, METH_VARARGS, - "Terminate process by PID."}, - {"killhandle", win32pm_killhandle, METH_VARARGS, - "Terminate process by windows process handle."}, - {NULL, NULL, 0, NULL} /* Sentinel */ -}; - -PyMODINIT_FUNC -initwin32pm(void) -{ - Py_InitModule("win32pm", win32pmMethods); -}