Skip to content

Async event loop halts execution when not running async functions #5021

Closed as not planned
@ygorpontelo

Description

@ygorpontelo

The current implementation for integrating async functions use loop.run_until_complete. This function runs the event loop until the result from the coroutine is done and then halts the execution of the event loop. This causes any scheduled coroutines to to also halt execution. This is not too bad because every time you run another coroutine, the execution resumes, but this is not ideal.

The idea is to maintain current behaviour when executing async functions, but when the coroutine finishes, the loop somehow continues to execute in the background. This way, the coroutines scheduled are not blocked by the main thread.

I have an implementation that i think could solve this issue. It starts a thread that runs the event loop in the background when robot is executing normal keywords. If the keyword is async, this threads stops and robot runs as usual, once the result is done we start another thread and repeat the process.

Unfortunally, this is still not truly parallel execution because threads in python have the GIL and event loops cannot be serialized for us to use multiprocessing, i tried but didn't succeed. Nevertheless any IO bound code will not halt the execution of the event loop anymore, this includes functions like sleep not blocking coroutines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions