Salome HOME
[EDF27816] Management of double foreach and management of proxyfile lifecycle
[modules/yacs.git] / src / runtime / PythonNode.hxx
index fdac25950efd5bcdbc0889c97a714e5f22e7a726..d83997cde3a257b07385da8baf77f41665dfa524 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -34,6 +34,13 @@ namespace YACS
   {
     class YACSRUNTIMESALOME_EXPORT PythonEntry
     {
+    public:
+      static bool IsProxy( PyObject *ob );
+      /*! return true only if ob is a proxy and destroy flag set to true*/
+      static bool GetDestroyStatus( PyObject *ob );
+      static void DoNotTouchFileIfProxy( PyObject *ob );
+      static void UnlinkOnDestructorIfProxy( PyObject *ob );
+      static void IfProxyDoSomething( PyObject *ob, const char *meth );
     protected:
       PythonEntry();
       ~PythonEntry();
@@ -46,15 +53,19 @@ namespace YACS
       virtual const char *getSerializationScript() const = 0;
       //
       void commonRemoteLoad(InlineNode *reqNode);
-      void commonRemoteLoadPart1(InlineNode *reqNode);
-      Engines::Container_var commonRemoteLoadPart2(InlineNode *reqNode, bool& isInitializeRequested);
-      void commonRemoteLoadPart3(InlineNode *reqNode, Engines::Container_ptr objContainer, bool isInitializeRequested);
+      void loadRemoteContainer(InlineNode *reqNode);
+      Engines::Container_var loadPythonAdapter(InlineNode *reqNode, bool& isInitializeRequested);
+      void loadRemoteContext(InlineNode *reqNode, Engines::Container_ptr objContainer, bool isInitializeRequested);
       static std::string GetContainerLog(const std::string& mode, Container *container, const Task *askingTask);
+      virtual bool hasImposedResource()const;
     protected:
       PyObject *_context;
       PyObject *_pyfuncSer;
       PyObject *_pyfuncUnser;
       PyObject *_pyfuncSimpleSer;
+      static PyObject *_pyClsBigObject;
+      std::string _imposedResource;
+      std::string _imposedContainer;
     public:
       static const char SCRIPT_FOR_SIMPLE_SERIALIZATION[];
     };
@@ -69,11 +80,15 @@ namespace YACS
       void assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp);
       Engines::PyNodeBase_var getRemoteInterpreterHandle();
       const char *getSerializationScript() const  { return SCRIPT_FOR_SERIALIZATION; }
+      // A kernel container may manage several python contexts identified by
+      // their name (PyNode and PyScript node). This function returns  the name
+      // of the context used by this object. See SALOME_Component.idl in KERNEL.
+      std::string pythonEntryName()const;
     public:
       PythonNode(const PythonNode& other, ComposedNode *father);
       PythonNode(const std::string& name);
       virtual ~PythonNode();
-      virtual void checkBasicConsistency() const throw(Exception);
+      virtual void checkBasicConsistency() const ;
       virtual void execute();
       virtual void load();
       virtual void loadRemote();
@@ -81,10 +96,24 @@ namespace YACS
       virtual void executeRemote();
       virtual void executeLocal();
       virtual void shutdown(int level);
+      void imposeResource(const std::string& resource_name,
+                          const std::string& container_name) override;
+      bool canAcceptImposedResource()override;
+      bool hasImposedResource()const override;
+      bool isUsingPythonCache()const;
       std::string getContainerLog();
       PythonNode* cloneNode(const std::string& name);
       virtual std::string typeName() { return "YACS__ENGINE__PythonNode"; }
       void applyDPLScope(ComposedNode *gfn);
+      void setSqueezeStatus(bool sqStatus) { _autoSqueeze=sqStatus; }
+      bool getSqueezeStatus() const { return _autoSqueeze; }
+      void squeezeMemorySafe();
+    private:
+      void executeLocalInternal(const std::string& codeStr);
+    protected:
+      void squeezeMemory();
+      void squeezeMemoryRemote();
+      void freeKernelPynode();
     public:
       static const char KIND[];
       static const char IMPL_NAME[];
@@ -92,6 +121,7 @@ namespace YACS
       static const char REMOTE_NAME[];
       static const char DPL_INFO_NAME[];
     protected:
+      bool _autoSqueeze = false;
       Engines::PyScriptNode_var _pynode;
     };
 
@@ -110,7 +140,7 @@ namespace YACS
       PyFuncNode(const std::string& name);
       virtual ~PyFuncNode();
       virtual void init(bool start=true);
-      virtual void checkBasicConsistency() const throw(Exception);
+      virtual void checkBasicConsistency() const ;
       virtual void execute();
       virtual void load();
       virtual void loadRemote();
@@ -118,6 +148,10 @@ namespace YACS
       virtual void executeRemote();
       virtual void executeLocal();
       virtual void shutdown(int level);
+      void imposeResource(const std::string& resource_name,
+                          const std::string& container_name) override;
+      bool canAcceptImposedResource()override;
+      bool hasImposedResource()const override;
       std::string getContainerLog();
       PyFuncNode* cloneNode(const std::string& name);
       virtual std::string typeName() { return "YACS__ENGINE__PyFuncNode"; }