Skip to content

Instantly share code, notes, and snippets.

@simryang
Created September 22, 2023 01:03
Show Gist options
  • Save simryang/401ccbacc9764edb05d3bfd0e955c155 to your computer and use it in GitHub Desktop.
Save simryang/401ccbacc9764edb05d3bfd0e955c155 to your computer and use it in GitHub Desktop.
example for how to do remote ssh command via asyncssh/asyncio
import time
import asyncssh
import asyncio
params = range(10)
async def run():
async with asyncssh.connect("localhost", 8090, username="tester", password="t35t3r", known_hosts=None) as conn:
for param in params:
await conn.create_process(f"nohup very_very_long_run.sh {param} &")
async def main(loop):
await asyncio.sleep(0)
t1 = loop.create_task(run())
await t1
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment