Author Alisue Lambda
Recipients Alisue Lambda, asvetlov, yselivanov
Date 2018-04-24.17:21:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1524590485.25.0.682650639539.issue33350@psf.upfronthosting.co.za>
In-reply-to
Content
I've found an workaround. The point is that 'with s' should be included in a coroutine which will be timed-out.

    import asyncio
    import socket

    ADDR = ('10.0.2.1', 22)


    async def check(loop):
        s = socket.socket(socket.AF_INET,
                        socket.SOCK_STREAM)
        s.setblocking(False)
        with s:
            await loop.sock_connect(s, ADDR)


    async def test(loop):
        try:
            await asyncio.wait_for(
                check(loop),
                timeout=3,
                loop=loop,
            )
        except Exception as e:
            print('Fail: %s' % e)
        else:
            print('Success')


    if __name__ == '__main__':
        loop = asyncio.get_event_loop()
        loop.run_until_complete(test(loop))
History
Date User Action Args
2018-04-24 17:21:25Alisue Lambdasetrecipients: + Alisue Lambda, asvetlov, yselivanov
2018-04-24 17:21:25Alisue Lambdasetmessageid: <1524590485.25.0.682650639539.issue33350@psf.upfronthosting.co.za>
2018-04-24 17:21:25Alisue Lambdalinkissue33350 messages
2018-04-24 17:21:25Alisue Lambdacreate