]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Win32: remove obsolete win32pm implementation
authorana <ana@opencascade.com>
Tue, 13 Oct 2015 12:22:19 +0000 (15:22 +0300)
committerana <ana@opencascade.com>
Tue, 13 Oct 2015 12:22:19 +0000 (15:22 +0300)
bin/killSalomeWithPort.py
bin/runSalome.py
bin/salome_utils.py
bin/server.py
src/Container/SALOME_ContainerManager.cxx
src/win32pm/setup.py [deleted file]
src/win32pm/win32pm.c [deleted file]

index d973eae0079ba35deaf3f227d6e397cb2862a884..95497f0dbefe80091c4591fdd648211e5516122e 100755 (executable)
@@ -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
index 50310e9d66686a892e150186bfd8ddf119b08c5e..22af40af1e4329760eb3a2001a5afeeccea90464 100755 (executable)
@@ -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
 
index 090332386cefc093952de6142052c13314f0ebe4..cf87ef39d3c055ee6bcacd2498865018456d44b3 100644 (file)
@@ -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
 # --
index dcb9488f4068787b081217c6ee680cfe783a58e8..fc36db0a477c901eccacad4b4fc61e4d2bb83141 100755 (executable)
@@ -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
index 23ff57b319fca46be1a5da3dbb63654acb638c1d..0072c24435fef010576eab033c04b47570598671 100644 (file)
@@ -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 (executable)
index 483eb2f..0000000
+++ /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 (executable)
index a740a41..0000000
+++ /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 <Python.h>
-#include <windows.h>
-
-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);
-}