*** Settings ***
Library AsyncLibrary
*** Test Cases ***
Example Test
${handle} async run Task1
${handle2} async run Task2
Log Both tasks have finished
*** Keywords ***
Task1
Log Task 1 started
Sleep 2
Log Task 1 finished
Task2
Log Task 2 started
Sleep 3
Log Task 2 finished
error:
Example Test
Exception in thread Thread-1 (wrapped_f):
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\threading.py", line 1009, in _bootstrap_inner
.Exception in thread Thread-2 (wrapped_f):
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\threading.py", line 1009, in _bootstrap_inner
First time seeing that library but it looks useful, thanks for finding it
As I’ve not seen it before, I’m not an expert, however from a quick look at the library README and the code I thing I understand what is happening.
With threading you should wait for the thread to end before exiting the process that created that thread, in your case you are starting 2 threads ( async run) , logging some text to the log and exiting so the main process ( Example Test) is finishing before the threads ( Task1 and Task2) which would explain those errors.
Here’s a suggestion for a slightly modified test that should hopefully work better as it should wait for the threads to finish.
*** Settings ***
Library AsyncLibrary
*** Test Cases ***
Example Test
${handle} async run Task1
${handle2} async run Task2
Log Both tasks have started
${return_value1} async get ${handle}
${return_value2} async get ${handle2}
Log Both tasks have finished
*** Keywords ***
Task1
Log Task 1 started
Sleep 2
Log Task 1 finished
Task2
Log Task 2 started
Sleep 3
Log Task 2 finished
Hi Dave By using the above code which you have provided the execution is not terminating and i have used log to console instead of log but not able to see the log statement. and i have to terminate the process manually to stop the execution.
Ok I setup a VM with a minimal Debian 11 and installed pip, then ran robotframework-async copied my example and ran it to reproduce your issue.
Here’s what i got:
dave@Harsha:~/tmp$ robot --version
Robot Framework 6.0.2 (Python 3.9.2 on linux)
dave@Harsha:~/tmp$
dave@Harsha:~/tmp$ robot Harsha-AsyncLibrary.robot
==============================================================================
Harsha-AsyncLibrary
==============================================================================
Example Test Both tasks have started
.Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
.Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
.Both tasks have started
.^CSecond signal will force exit.
Example Test | FAIL |
Execution terminated by signal
------------------------------------------------------------------------------
Harsha-AsyncLibrary | FAIL |
1 test, 0 passed, 1 failed
==============================================================================
Output: /home/dave/tmp/output.xml
Log: /home/dave/tmp/log.html
Report: /home/dave/tmp/report.html
dave@Harsha:~/tmp$
Hi Robot Forum, I used the fork of the AsyncLibrary and I have the error in VSCode, that the Library import cannot be resolved.
Library AsyncLibrary
Unresolved library: AsyncLibrary.
Error generating libspec:
Importing library 'AsyncLibrary' failed: ModuleNotFoundError: No module named 'AsyncLibrary'
Consider adding the needed paths to the "robot.pythonpath" setting
and calling the "Robot Framework: Clear caches and restart" action.robotframework
Error generating libspec:
Initializing library ‘AsyncLibrary’ with no arguments failed: RobotNotRunningError: Cannot access execution context
robotframework
That feels like the issue is triggered by the LSP Server and implementation not taking that into account and by a brief look, this seems to be the case.
When LSP tries to get a list of keywords from the Library, it calls the library’s constructor. If any part of the call chain for that constructor calls any robot framework API’s that requires RF to be running, this will cause that constructor call to fail for that “RobotNotRunningError”.
Thank you for the explanation.
It somehow makes calling library keywords not working in VSCode.
Which implantation of get_context() can I use to fix the error?