[sr-dev] git:master:34d60608: app_python3: docs - added note about how Python modules used in script can be reloaded

Daniel-Constantin Mierla miconda at gmail.com
Tue Nov 15 17:25:47 CET 2022


Module: kamailio
Branch: master
Commit: 34d60608bea449ab7258a5d88894651303b80adf
URL: https://github.com/kamailio/kamailio/commit/34d60608bea449ab7258a5d88894651303b80adf

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2022-11-15T17:24:23+01:00

app_python3: docs - added note about how Python modules used in script can be reloaded

---

Modified: src/modules/app_python3/doc/app_python3_admin.xml

---

Diff:  https://github.com/kamailio/kamailio/commit/34d60608bea449ab7258a5d88894651303b80adf.diff
Patch: https://github.com/kamailio/kamailio/commit/34d60608bea449ab7258a5d88894651303b80adf.patch

---

diff --git a/src/modules/app_python3/doc/app_python3_admin.xml b/src/modules/app_python3/doc/app_python3_admin.xml
index 0f4c63ffd0..67f6058020 100644
--- a/src/modules/app_python3/doc/app_python3_admin.xml
+++ b/src/modules/app_python3/doc/app_python3_admin.xml
@@ -203,12 +203,12 @@ python_exec("my_python_function", "$rU");
             <para>
             Marks the need to reload the Python script.
             The actual reload is done in each worker when it next invokes a Python method.
-            The module uses a worker process lock to prevent recursive reloads. 
+            The module uses a worker process lock to prevent recursive reloads.
             </para>
             <para>
-              This function only reloads the user script and creates a new script object.
-	      It does not reinitialize the interpreter.
-	      E.g., references in the old module remain if not redefined by the new version.
+			This function only reloads (re-executes) the user script and creates
+			a new script object. It does not reinitialize the interpreter (references
+			in the old module remain if not redefined by the new version).
             </para>
             <para>
             Name: <emphasis>app_python.reload</emphasis>
@@ -222,6 +222,28 @@ python_exec("my_python_function", "$rU");
 &kamcmd; app_python.reload
 ...
             </programlisting>
+			<para>
+			Note that reload is done for the Python script provided as parameter
+			to this &kamailio; module. To reload the Python libraries imported
+			in this script, use something like:
+            </para>
+            <programlisting  format="linespecific">
+...
+import mod1
+...
+import modN
+from importlib import reload
+
+def mod_init():
+    reload(mod1)
+    ...
+    reload(modN)
+    return kamailio()
+...
+            </programlisting>
+			<para>
+				Where "modX" are the modules imported at the top.
+            </para>
 		</section>
 		<section id="app_python3.r.api_list">
             <title>




More information about the sr-dev mailing list