diff --git a/src/backend/pyloader/Policy.py b/src/backend/pyloader/Policy.py index 6a18d01..af469a1 100644 --- a/src/backend/pyloader/Policy.py +++ b/src/backend/pyloader/Policy.py @@ -1,8 +1,6 @@ - -import sgpem from Abstract import * -class Policy(sgpem.Policy): +class Policy: ## @var Avoid instantiation of an abstract class __metaclass__ = Metaclass @@ -10,3 +8,4 @@ class Policy(sgpem.Policy): sort_queue = AbstractMethod('sort_queue') is_preemptive = AbstractMethod('is_preemptive') is_time_sliced = AbstractMethod('is_time_sliced') + diff --git a/src/backend/pyloader/python_policy_manager.cc b/src/backend/pyloader/python_policy_manager.cc index 472308d..0a026a7 100644 --- a/src/backend/pyloader/python_policy_manager.cc +++ b/src/backend/pyloader/python_policy_manager.cc @@ -26,8 +26,8 @@ using namespace sgpem; //static object PythonPolicyManager* PythonPolicyManager::_instance = NULL; - -PythonPolicyManager::PythonPolicyManager() //private constructor. The parameter is discarded +PythonPolicyManager::PythonPolicyManager() + : _initialized(false) { } @@ -35,7 +35,7 @@ PythonPolicyManager& PythonPolicyManager::get_instance() { if(!_instance) - _instance = new PythonPolicyManager(); + _instance = new PythonPolicyManager(); return *_instance; } @@ -49,23 +49,21 @@ PythonPolicyManager::get_policy() void PythonPolicyManager::init() { - static bool initialized = false; - - if(initialized) - Py_Finalize(); - - Py_Initialize(); - initialized = true; - - // The following line is ugly, but necessary if we use - // non-standard installation directories. Theoretically, - // it should be up to the user to set correct - // environment variables. - // FIXME: find better way to achieve this. - - PyRun_SimpleString("import sys\n" - "sys.path[:0] = [ '" MODDIR "', '" PYCDIR "' ]\n"); - + if(_initialized) + Py_Finalize(); + + Py_Initialize(); + _initialized = true; + + // The following line is ugly, but necessary if we use + // non-standard installation directories. Theoretically, + // it should be up to the user to set correct + // environment variables. + // FIXME: find better way to achieve this. + + PyRun_SimpleString("import sys\n" + "sys.path[:0] = [ '" MODDIR "', '" PYCDIR "' ]\n"); + } diff --git a/src/backend/pyloader/python_policy_manager.hh b/src/backend/pyloader/python_policy_manager.hh index ed9df3e..66c4a34 100644 --- a/src/backend/pyloader/python_policy_manager.hh +++ b/src/backend/pyloader/python_policy_manager.hh @@ -30,24 +30,28 @@ namespace sgpem { - //class PolicyManager; - class PythonPolicyManager; + //class PolicyManager; + class PythonPolicyManager; - class SG_DLLEXPORT PythonPolicyManager : public PolicyManager - { - public: - - Policy& get_policy(); - void init(); - PyObject* get_py_dict(); + class SG_DLLEXPORT PythonPolicyManager : public PolicyManager + { + public: + Policy& get_policy(); + void init(); + PyObject* get_py_dict(); - static PythonPolicyManager& get_instance(); + static PythonPolicyManager& get_instance(); - private: - PythonPolicyManager(); //dummy parameter - static PythonPolicyManager* _instance; - std::auto_ptr _python_policy; - }; + private: + PythonPolicyManager(); + PythonPolicyManager(const PythonPolicyManager&); + PythonPolicyManager& operator=(const PythonPolicyManager&); + + static PythonPolicyManager* _instance; + std::auto_ptr _python_policy; + + bool _initialized; + }; }