Created attachment 191079 [details] This is the error when trying to open an embedded Python script Calling an embedded Python script from a Basic script does not work. The same script can be called without error if it is in the user location. The problems seems related to the "document" location. The script has been embedded with APSO v1.3.3. Here is the calling Basic code : REM ***** BASIC ***** Function bridge(fonction_py, param1, Optional param2, Optional param3) Dim myScript as Object Dim chemin As String 'The user location is working : 'chemin = "vnd.sun.star.script:Module.py$" & fonction_py & "?language=Python&location=user" 'The document location does not work chemin = "vnd.sun.star.script:Module.py$" & fonction_py & "?language=Python&location=document" myScript = ThisComponent.getScriptProvider().getScript(chemin) bridge = myScript.invoke(Array(param1, param2, param3), Array(), Array() ) End Function
(In reply to Olivier from comment #0) > 'The document location does not work > chemin = "vnd.sun.star.script:Module.py$" & fonction_py & > "?language=Python&location=document" Where in the document package does is Module.py located? Note https://wiki.documentfoundation.org/Documentation/DevGuide/Scripting_Framework#Python_script , where the common case is described as: > the Python module myModule.py is stored in directory Scripts/python of the user > or share directory of the installation, or of the document. Please provide a sample document with both Python module, and a Basic macro trying to call it.
Created attachment 191080 [details] Sample document with a non working Python Call Here is a sample document where the Basic errors trig. After opening the document, enabling macros and confirming the Basic errors, i've just discovered that copying the 3 cells D3, D5 and D6 in another other place solve the problem. After opening, please try to copy D3, D5 and D6 to another location, for example D9, then you should see that the Python script call start to work. If you did copy the three cells at D9 location, You should get the Python script results inside cells D11 and 12, values should be 100 and 200. But the initial cells D5 and D6 will still stay empty.
I've found the root cause of the problem. When opening the document the Sheet formulas are refreshing before the Basic script got enough time to load the Python Script. Disabling the autorefresh in the data menu solve the problem. Then pressing F9 run the basic script normally without error. After that, enabling again autorefresh does not cause problems. This show that the problem exhibit only at the opening of the document. It probably does come from a missing process synchronization check.
See also bug 79588 comment 29. But that comment only discusses how the UDF are recognized; and this problem here is not about UDF recognition, but about the first execution of spreadsheet formulas. Likely this is a duplicate of bug 122545.
You are right this is probably a duplicate of the bug 122545 that is here since 2019 and has not been fixed. It's probably definitely a problem with a missing process or thread synchronization. Because if autocalculate is disabled when opening the document the error does not exhibit. Probably, Basic try to execute Python code before the Python object has been loaded. The processor load during document opening is probably the reason that trig this error. Should be solved by adding a semaphore so that Basic do not try to run code from another yet unloaded object for another language.
*** This bug has been marked as a duplicate of bug 122545 ***