@@ -99,8 +99,6 @@ const std::string DYNAMIC_PEP_RULE_REGEX = "[^ ]*pep_[^ ]*_(pre|post)";
9999
100100namespace bp = boost::python;
101101
102- static std::recursive_mutex python_mutex;
103-
104102namespace
105103{
106104 static inline constexpr const char * const rule_engine_name = " python" ;
@@ -422,42 +420,37 @@ namespace
422420static irods::error start (irods::default_re_ctx&, const std::string& _instance_name)
423421{
424422 python_state::ts_main = nullptr ;
425- {
426- std::lock_guard<std::recursive_mutex> lock{python_mutex};
427- // lock needs to stay in scope for extract_python_exception
428- // hence the weird nesting here
429- try {
430- PyImport_AppendInittab (" plugin_wrappers" , &PyInit_plugin_wrappers);
431- PyImport_AppendInittab (" irods_types" , &PyInit_irods_types);
432- PyImport_AppendInittab (" irods_errors" , &PyInit_irods_errors);
423+ try {
424+ PyImport_AppendInittab (" plugin_wrappers" , &PyInit_plugin_wrappers);
425+ PyImport_AppendInittab (" irods_types" , &PyInit_irods_types);
426+ PyImport_AppendInittab (" irods_errors" , &PyInit_irods_errors);
433427
434- initialize_python (_instance_name);
428+ initialize_python (_instance_name);
435429
436- bp::object plugin_wrappers = bp::import (" plugin_wrappers" );
437- bp::object irods_types = bp::import (" irods_types" );
438- bp::object irods_errors = bp::import (" irods_errors" );
439-
440- StringFromPythonUnicode::register_converter ();
441- }
442- catch (const bp::error_already_set&) {
443- const std::string formatted_python_exception = extract_python_exception ();
444- // clang-format off
445- log_re::error ({
446- {" rule_engine_plugin" , rule_engine_name},
447- {" instance_name" , _instance_name},
448- {" log_message" , " caught python exception" },
449- {" python_exception" , formatted_python_exception},
450- });
451- // clang-format on
452- std::string err_msg = std::string (" irods_rule_engine_plugin_python::" ) + __PRETTY_FUNCTION__ +
453- " Caught Python exception.\n " + formatted_python_exception;
454- return ERROR (RULE_ENGINE_ERROR, err_msg);
455- }
430+ bp::object plugin_wrappers = bp::import (" plugin_wrappers" );
431+ bp::object irods_types = bp::import (" irods_types" );
432+ bp::object irods_errors = bp::import (" irods_errors" );
456433
457- python_state::ts_main = PyEval_SaveThread ();
458- // NO MORE PYTHON IN THIS FUNCTION PAST THIS POINT
434+ StringFromPythonUnicode::register_converter ();
435+ }
436+ catch (const bp::error_already_set&) {
437+ const std::string formatted_python_exception = extract_python_exception ();
438+ // clang-format off
439+ log_re::error ({
440+ {" rule_engine_plugin" , rule_engine_name},
441+ {" instance_name" , _instance_name},
442+ {" log_message" , " caught python exception" },
443+ {" python_exception" , formatted_python_exception},
444+ });
445+ // clang-format on
446+ std::string err_msg = std::string (" irods_rule_engine_plugin_python::" ) + __PRETTY_FUNCTION__ +
447+ " Caught Python exception.\n " + formatted_python_exception;
448+ return ERROR (RULE_ENGINE_ERROR, err_msg);
459449 }
460450
451+ python_state::ts_main = PyEval_SaveThread ();
452+ // NO MORE PYTHON IN THIS FUNCTION PAST THIS POINT
453+
461454 // Initialize microservice table
462455 irods::ms_table& ms_table = get_microservice_table ();
463456 // writeLine is not in the microservice table in 4.2.0 - #3408
@@ -537,7 +530,6 @@ static irods::error stop(irods::default_re_ctx&, const std::string&)
537530static irods::error rule_exists (const irods::default_re_ctx&, const std::string& rule_name, bool & _return)
538531{
539532 _return = false ;
540- std::lock_guard<std::recursive_mutex> lock{python_mutex};
541533 python_gil_lock gil_lock;
542534 try {
543535 // TODO Enable non core.py Python rulebases
@@ -558,7 +550,7 @@ static irods::error rule_exists(const irods::default_re_ctx&, const std::string&
558550 return ERROR (RULE_ENGINE_ERROR, err_msg);
559551 }
560552 // NOTE: If adding more catch blocks, nest this try/catch in another try block
561- // along with the lock and gil_lock definitions . They need to stay in-scope for extract_python_exception,
553+ // along with the gil_lock definition . They need to stay in-scope for extract_python_exception,
562554 // but should be out of scope for other exception handlers.
563555
564556 return SUCCESS ();
@@ -567,9 +559,8 @@ static irods::error rule_exists(const irods::default_re_ctx&, const std::string&
567559static irods::error list_rules (const irods::default_re_ctx&, std::vector<std::string>& rule_vec)
568560{
569561 try {
570- std::lock_guard<std::recursive_mutex> lock{python_mutex};
571562 python_gil_lock gil_lock;
572- // gil_lock (and therefore also lock) needs to stay in scope for extract_python_exception
563+ // gil_lock needs to stay in scope for extract_python_exception
573564 // hence the nested exception handling
574565 try {
575566 bp::object core_module = bp::import (" core" );
@@ -634,9 +625,8 @@ static irods::error exec_rule(const irods::default_re_ctx&,
634625 irods::callback effect_handler)
635626{
636627 try {
637- std::lock_guard<std::recursive_mutex> lock{python_mutex};
638628 python_gil_lock gil_lock;
639- // gil_lock (and therefore also lock) needs to stay in scope for extract_python_exception
629+ // gil_lock needs to stay in scope for extract_python_exception
640630 // hence the nested exception handling
641631 try {
642632 // TODO Enable non core.py Python rulebases
@@ -761,9 +751,8 @@ static irods::error exec_rule_text(const irods::default_re_ctx&,
761751 }
762752
763753 try {
764- std::lock_guard<std::recursive_mutex> lock{python_mutex};
765754 python_gil_lock gil_lock;
766- // gil_lock (and therefore also lock) needs to stay in scope for extract_python_exception
755+ // gil_lock needs to stay in scope for extract_python_exception
767756 // hence the nested exception handling
768757 try {
769758 execCmdOut_t* myExecCmdOut = (execCmdOut_t*) malloc (sizeof (*myExecCmdOut));
@@ -915,9 +904,8 @@ static irods::error exec_rule_expression(irods::default_re_ctx&,
915904 irods::callback effect_handler)
916905{
917906 try {
918- std::lock_guard<std::recursive_mutex> lock{python_mutex};
919907 python_gil_lock gil_lock;
920- // gil_lock (and therefore also lock) needs to stay in scope for extract_python_exception
908+ // gil_lock needs to stay in scope for extract_python_exception
921909 // hence the nested exception handling
922910 try {
923911 bp::dict rule_vars_python;
0 commit comments