-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Async support to dynamic and hybrid library APIs #4803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello, i helped implement async in robot. You shouldn't need to grab the context to work with async, can you elaborate more on what Robot is not being able to do? Like example of such keywords that is not being able to get the results. |
Hello, as an example: *** Settings ***
Library test_async.py
*** Test Cases ***
Test 1
async_keyword library: from asyncio import sleep
class test_async:
async def get_keyword_names(self):
await sleep(1)
return ["async_keyword"]
async def async_keyword(self):
await sleep(1)
return "test" When you try to start this test you will get:
|
Ah i see, these methods that are available for a dynamic library must be normal functions as specified in the interface: https://github.com/robotframework/robotframework/blob/master/src/robot/api/interfaces.py#L104 In the example you gave, it should be like this:
Every method in that interface must be a normal function too. If you need to run something async in those normal methods, i would suggest you use asyncio.run(). An example would be:
I would try to avoid this however, because resources would have a separate event loop that get's closed once run is done. This is not a problem if the coroutine return resources that are not attached to the event loop, like primitive types for example. TLDR: The methods in the interface must be normal functions. If you need to run an async function inside those and it returns something that don't require the event loop anymore, just use asyncio.run(). Otherwise avoid this and try to run that async function elsewhere. |
May have found a way to make it async, follow the PR. |
Thank you for looking at it. This works as expected. |
This looks like a good enhancement and the implementation in the PR looks good as well. The PR lacks tests, though, and I believe this should also be mentioned in the User Guide. We are currently developing RF 7 with a plan to get it out in early December. I hope we could get this and #4808 done before that! |
Implemented by PR #4836. Thanks for another great contribution @ygorpontelo! |
Issue #4089 that added the initial async support was given a high priority and I guess this issue deserves it as well. Priorities don't matter much with issues that are already done, but this way we remember to mention this in the release notes. It would be interesting to hear what kind of use cases you @WisniewskiP have for the async dynamic API. |
Thanks for adding it to RF. We are using RF as frontend to our testing device. it is communicating over network similar to remote lib, but we are using async framework for this communication because we need concurrent access and authentication. |
For our Lib we are using framework that is async and we have to await for results.
our lib works similar to Remote Lib to get the keywords and arguments but communication is done using asyncio.
with RF 6.1 run_keyword can be made async but functions for getting keywords/arguments/etc. can't.
as a workaround I'm getting context with EXECUTION_CONTEXTS.current and run async operations with context.asynchronous.run_until_complete().
this works but if the implementation of EXECUTION_CONTEXTS changes the library will break.
would it be possible to add async to get_* functions in Dynamic & Hybrid Lib interfaces?
The text was updated successfully, but these errors were encountered: