Using asyncio with rpaframework

I’m testing if I could use Python asyncio to speed up execution. Trying something really simple:

But I got the following error. Any idea?

Task exception was never retrieved
future: <Task finished coro=<first_name() done, defined at D:/OneDrive/OneDrive KSL/RPA/Scratch/Practice Asynch/Async RPA.py:4> exception=TypeError(“object NoneType can’t be used in ‘await’ expression”)>
Traceback (most recent call last):
File “D:/OneDrive/OneDrive KSL/RPA/Scratch/Practice Asynch/Async RPA.py”, line 5, in first_name
await s.input_text(“//input[@ng-reflect-name=‘labelFirstName’]”, “John”)

TypeError: object NoneType can’t be used in ‘await’ expression
Task exception was never retrieved
future: <Task finished coro=<last_name() done, defined at D:/OneDrive/OneDrive KSL/RPA/Scratch/Practice Asynch/Async RPA.py:7> exception=TypeError(“object NoneType can’t be used in ‘await’ expression”)>

To be able to use await, those functions that are “awaited” must be async functions, and my understanding is that robotframework, rpaframework, and selenium library does not support asyncio right out of the box.

If you want to use asyncio, you have to do it mostly yourself. You can use RF and RPA libraries as “plain python functions” inside your asyncio functions, but they can/will block and do not contribute to asyncio concurrency.

At least this is my understanding. If someone has different view, please chime in.

Sorry.

Could you elaborate on what this sentence mean - “but they can/will block and do not contribute to asyncio concurrency”?

asyncio in python are coroutines, and those things should use “non-blocking” things for IO and processes etc.

When using normal python code, file io, network io, and subprocess execution all are implemented in blocking fashion. And those wont play nicely with asyncio world, and will block.

For more information, read python documentation:

1 Like

As Jippo stated, to work with async code (efficiently at least) all your code have to be async ready (awaitable functions aka the function call returns a coroutine, which is not the case with Selenium). But I know there are ways to wrap a sync function (like the input_text in your example) into a thread whose Future can be wrapped into an awaitable coroutine. (example)
And I believe asyncio.to_thread is even better.

As an alternative, maybe gevent’s pseudo-threads will help you here.