*** 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$