Skip to content

How to change connection timeout interval? #409

Answered by ronf
StanSvec asked this question in Q&A
Discussion options

You must be logged in to vote

I got a chance to look at this again tonight, and the asyncio.wait_for() approach does work here. I was in a rush when I tested it this morning, and wasn't running the test client I thought I was. Here's an example:

import asyncio, asyncssh, sys

async def run_client():
    try:
        conn = await asyncio.wait_for(asyncssh.connect('10.1.2.3'), timeout=3)
    except asyncio.TimeoutError:
        sys.exit('Timeout')

    async with conn:
        print((await conn.run('tty', term_type='ansi')).stdout, end='')

asyncio.run(run_client())

If you don't need to catch the TimeoutError separately for just the connect() call, you can use the asyncio.wait_for() directly in an "async with". For inst…

Replies: 5 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by StanSvec
Comment options

You must be logged in to vote
1 reply
@ronf
Comment options

Comment options

You must be logged in to vote
1 reply
@anthonyjmartinez
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants