*** Test Cases ***
Test Async
${task1} = Start Async long task one ${10}
${task2} = Start Async long task two ${5}
${task3} = Start Async long task three ${3}
${text2} = Get Async ${task2}
Log To Console ${text2}
${text1} = Get Async ${task1}
Log To Console ${text1}
${text3} = Get Async ${task3}
Log To Console ${text3}
## Implementation
from uuid import uuid4
from robot.libraries.BuiltIn import BuiltIn
from concurrent.futures import ThreadPoolExecutor
def method_instance_for_keyword_name(keyword_name):
robot_libraries = BuiltIn().get_library_instance(all=True)
for lib in robot_libraries:
methods = [method for method in dir(robot_libraries[lib])]
if keyword_name in methods:
return getattr(robot_libraries[lib], method)
class Async:
def __init__(self):
self._futures = {}
self.executor = ThreadPoolExecutor(max_workers=10)
def start_async(self, keyword, *args, **kwargs):
handle = uuid4()
keyword_name_to_find = keyword.replace(" ", "_")
method = method_instance_for_keyword_name(keyword_name_to_find)
self._futures[handle] = self.executor.submit(method, *args, **kwargs)
return handle
def get_async(self, handle):
result = self._futures[handle].result()
return result
Ugh
I understand your need but many libraries are not build to support threads or multi processing. So blindly just wrapping keywords in thread may not be the best idea. Perhaps you could get the same result by starting the task as background process. In this way you could have many tasks running in the same time and wait for the task completion. If task can be started as process, the Process [1] library could be the easiest solution.
-Tatu
[1] http://robotframework.org/robotframework/latest/libraries/Process.html
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.