Hi Ron,
Python 3.5 introduced new syntax to better support asynchronous programming.
Do you have any thoughts on how this new syntax can be used with AsyncSSH? Is it mostly a matter of making simple replacements like putting in await instead of yield from? Are there any potential benefits to using the new syntax apart from improved legibility?
Nick
Python 3.5 introduced new syntax to better support asynchronous programming.
Do you have any thoughts on how this new syntax can be used with AsyncSSH? Is it mostly a matter of making simple replacements like putting in
awaitinstead ofyield from? Are there any potential benefits to using the new syntax apart from improved legibility?
Good to see that using the new syntax with AsyncSSH as it stands today is straightforward!
Unfortunately, there are some deprecations in 3.5 which affect the AsyncSSH code, but I can’t switch to the new preferred syntax and still support version 3.4.0. One of the deprecations happened in 3.4.4 for instance, and only 3.4.4 and later have the replacement function (asyncio.ensure_future instead of asyncio.async). It would get messy to try and support both, and I’m not quite sure what to do about that.
Yeah, I noticed that deprecation too. Funny thing is 3.4.4 hasn’t even been released yet.
Once 3.5 becomes a bit more widely used, it might make sense to declare some version of AsyncSSH as the last version that supports Python 3.4 and then require users to start using 3.5 if they want newer versions of AsyncSSH.
The upgrade path from 3.4 to 3.5 is probably quite easy, but I’m sure it will nonetheless be a nuisance to users still on 3.4. In the long run, it might still pay off to force that upgrade if it means writing and maintaining AsyncSSH becomes easier more enjoyable for you and for other contributors.
I understand the tension though. Writing a library is tough business.
Nick
Good to see that using the new syntax with AsyncSSH as it stands today is straightforward!
Unfortunately, there are some deprecations in 3.5 which affect the AsyncSSH code, but I can’t switch to the new preferred syntax and still support version 3.4.0. One of the deprecations happened in 3.4.4 for instance, and only 3.4.4 and later have the replacement function (asyncio.ensure_future instead of asyncio.async). It would get messy to try and support both, and I’m not quite sure what to do about that.
Yeah, I noticed that deprecation too. Funny thing is 3.4.4 hasn’t even been released yet.
Once 3.5 becomes a bit more widely used, it might make sense to declare some version of AsyncSSH as the last version that supports Python 3.4 and then require users to start using 3.5 if they want newer versions of AsyncSSH.
The upgrade path from 3.4 to 3.5 is probably quite easy, but I’m sure it will nonetheless be a nuisance to users still on 3.4. In the long run, it might still pay off to force that upgrade if it means writing and maintaining AsyncSSH becomes easier more enjoyable for you and for other contributors.
Sounds like a plan. I’ve seen other projects maintain maintenance branches that they just backport critical fixes to as a courtesy to their users.
I may also start to experiment with some of the other 3.5 features in this release, like the ability to do type annotations.
By the way, you can do this in Python 3.0+. It’s just that in 3.5 they standardized the annotations under the typing module to make life easier for static type checkers like mypy.
Nick
Hey Ron,
Regarding this part of your example:
async def run_client():
with (await asyncssh.connect('localhost')) as conn:
chan, session = await conn.create_session(MySSHClientSession, 'ls abc')
await chan.wait_closed()
Would this be better expressed as follows?
async def run_client():
async with asyncssh.connect('localhost') as conn:
chan, session = await conn.create_session(MySSHClientSession, 'ls abc')
await chan.wait_closed()
One of the new pieces of syntax that got introduced alongside async and await is async with.
To support this, the connect() context manager would need to implement __aenter__() and __aexit__() methods, both of which return awaitables. I think these can be added in a backwards compatible fashion by using yield from, which is an awaitable.
Nick