Skip to content

got the error "got Future <Future pending> attached to a different loop" #633

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

You must be logged in to vote

You are still creating multiple event loops here, since you are calling asyncio.run() multiple times. You can't use any AsyncSSH objects created in the first call to asyncio.run() after that call returns, as the associated event loop stored inside the AsyncSSH objects will be closed at that point. Try changing from:

if __name__ == '__main__':
    driver_ssh = BCSSHDriver()
    asyncio.run(server_connection(driver_ssh))
    asyncio.run(run_command(driver_ssh))

to:

async def main():
    driver_ssh = BCSSHDriver()
    await server_connection(driver_ssh)
    await run_command(driver_ssh)

if __name__ == '__main__':
    asyncio.run(main())

The alternative would be to create an event loop and c…

Replies: 5 comments 6 replies

Comment options

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

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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

Answer selected by billychen2014
Comment options

You must be logged in to vote
4 replies
@billychen2014
Comment options

@ronf
Comment options

@billychen2014
Comment options

@ronf
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants