*/
pickledArgs execute(in string functionName, in pickledArgs inargs) raises (SALOME::SALOME_Exception);
- } ;
+ };
interface PyScriptNode : PyNodeBase
{
void finishPushContext() raises (SALOME::SALOME_Exception);
};
+ interface GlobalsHolder
+ {
+ /*!
+ Simply a key / val holder.
+ */
+ void setAttr(in string ctx, in pickledArgs glbsAttachedToCtx) raises (SALOME::SALOME_Exception);
+ pickledArgs getAttr(in string ctx) raises (SALOME::SALOME_Exception);
+ void execute(in listofstring args, out long returncode, out pickledArgs stdout, out pickledArgs stderr) raises (SALOME::SALOME_Exception);
+ };
};
#endif
SALOME_Container.py
SALOME_ContainerHelper.py
SALOME_ContainerPy.py
+ SALOME_GlobalsImpl.py
)
ADD_DEFINITIONS(${HDF5_DEFINITIONS} ${OMNIORB_DEFINITIONS})
install(FILES ${KernelContainer_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})
SALOME_INSTALL_SCRIPTS("${_swig_SCRIPTS}" ${SALOME_INSTALL_BINS} EXTRA_DPYS "${SWIG_MODULE_KernelContainer_REAL_NAME}")
-INSTALL(DIRECTORY ScriptsTemplate DESTINATION ${SALOME_KERNEL_INSTALL_RES_DATA})
\ No newline at end of file
+INSTALL(DIRECTORY ScriptsTemplate DESTINATION ${SALOME_KERNEL_INSTALL_RES_DATA})
+INSTALL(FILES salome_process_launcher salome_process_attach PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ DESTINATION ${SALOME_INSTALL_BINS} )
--- /dev/null
+# -*- coding: utf-8 -*-
+# Copyright (C) 2024 CEA, EDF
+#
+# 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
+#
+
+import Engines__POA
+
+class SALOME_GlobalsImpl(Engines__POA.GlobalsHolder):
+ def __init__(self):
+ self._map = {}
+
+ def setAttr(self, ctx, glbsAttachedToCtx):
+ self._map[ctx] = glbsAttachedToCtx
+
+ def getAttr(self, ctx):
+ return self._map[ctx]
+
+ def execute(self, args):
+ import subprocess as sp
+ proc = sp.Popen(args,stdout = sp.PIPE, stderr = sp.PIPE)
+ stdout, stderr = proc.communicate()
+ returncode = proc.returncode
+ return returncode, stdout, stderr
--- /dev/null
+#! /usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Copyright (C) 2024 CEA, EDF
+#
+# 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
+#
+
+# -ex bt
+# -x script.gdb
+# -nx to skip .gdbinit
+
+def GetRendezVous():
+ import sys
+ if len( sys.argv ) != 3:
+ raise RuntimeError("salome_process_attach have to take a rendez-vous file and gdb script")
+ return sys.argv[1],sys.argv[2]
+
+import salome
+salome.salome_init()
+rdv,gdbfile = GetRendezVous()
+remoteNS = salome.naming_service.LoadIORInFile(rdv)
+remoteGlbs = salome.orb.string_to_object( remoteNS.Resolve("PID_TO_TRACK").decode() )
+import pickle
+pidToTrack = pickle.loads( remoteGlbs.getAttr("CTX0") )["pid"]
+returncode, stdout, stderr = remoteGlbs.execute(["gdb","-batch","-x",gdbfile,"attach",str(pidToTrack)])
+st = f"""returnCode = {returncode}
+stdout = {stdout.decode()}
+stderr = {stderr.decode()}
+"""
+print(st)
--- /dev/null
+#! /usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Copyright (C) 2024 CEA, EDF
+#
+# 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
+#
+
+import signal
+import salome
+import sys
+import os
+
+salome.salome_init()
+
+proc = None
+
+def handler(signum, frame):
+ os.kill( proc.pid, signal.SIGKILL )
+
+from pathlib import Path
+import argparse
+parser = argparse.ArgumentParser()
+parser.add_argument("-rdv","--rendz-vous",dest = "rdv", type=Path, help="Mandatory filename used as a rendez-vous file",required=True)
+parser.add_argument('rest', nargs=argparse.REMAINDER, help="Process to be launched. Attachable using salome_process_attach")
+args = parser.parse_args()
+if args.rest[0] != "--":
+ raise RuntimeError("You have to preappend -- before commande to be launched")
+args.rest = args.rest[1:]
+salome.naming_service.DumpIORInFile( args.rdv )
+
+signal.signal(signal.SIGINT, handler)
+signal.signal(signal.SIGTERM, handler)
+import subprocess as sp
+proc = sp.Popen(args.rest ,cwd = os.getcwd())
+from SALOME_GlobalsImpl import SALOME_GlobalsImpl
+glbs = SALOME_GlobalsImpl()
+import pickle
+glbs.setAttr("CTX0",pickle.dumps({"pid":proc.pid}))
+poa = salome.orb.resolve_initial_references("RootPOA")
+id_o = poa.activate_object(glbs)
+refPtr = poa.id_to_reference(id_o)
+salome.naming_service.Register(refPtr,"PID_TO_TRACK")
+proc.communicate()
+sys.exit( proc.returncode )