Replace gevent with asyncio module
I belieave that replacing gevent with asyncio within pyInfra will make it easier to integrate pyInfra to more modern python projects. Me and some of my colleagues are willing to contribute if you are interested.
I'm keen on this too once Python 2 support is removed in v2 (https://github.com/Fizzadar/pyinfra/issues/329).
The connectors will also need support:
- SSH: replacement for
paramiko(https://github.com/ronf/asyncssh looks like a good option) - Local/docker: should just be able to use asyncio subprocess built into python3
- Winrm: unknown
Let's keep this issue open to track the work needed, I've just written the above list off the top of my head and needs further thought for sure. But definitely want to move in this direction and drop the gevent/monkey patching requirement.
IMHO asyncio is complicated and gevent is charmingly simple. This would be a huge task with very little benefit in terms of features. gevent is actively developed, and has great support for python3.
@oz123 I was literally just thinking this! Was doing some digging into unrelated things (parallelisation of operation calls) which uses gevent local objects and it turns out asyncio only has contextvars as of 3.7, which gevent references as so:
This module was added to Python 3.7. The gevent version is available on all supported versions of Python. However, see an important note about gevent 20.9.
Context variables are like greenlet-local variables, just more inconvenient to use. They were designed to work around limitations in asyncio and are rarely needed by greenlet-based code.
Despite this - I also do think that using asyncio would make pyinfra simpler to integrate with other proejcts. One of the most powerful pyinfra features is "being plain Python", but in reality it is not compatible with external asyncio projects (AFAIK, perhaps they do work to some degree).
There is also asyncio-gevent which attempts to make the two compatible, perhaps this is an option.
I can see advantages to both methods and am currently not particularly set on one or the other; keen to hear thoughts and opinions in this issue on the subject!