Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- async def run(cmd):
- proc = await asyncio.create_subprocess_shell(
- cmd,
- stdout=asyncio.subprocess.PIPE,
- stderr=asyncio.subprocess.PIPE)
- stdout, stderr = await proc.communicate()
- print(f'[{cmd!r} exited with {proc.returncode}]')
- if stdout:
- print(f'[stdout]\n{stdout.decode()}')
- if stderr:
- print(f'[stderr]\n{stderr.decode()}')
- def go_do_something(index):
- await run("sleep 2")
- def my_long_func(val: int) -> None:
- """
- This function contains a loop
- Each iteration of the loop calls a function
- Nothin is returned
- """
- for index in range(val):
- print("index = "+str(index))
- go_do_something(index)
- my_long_func(3) # launch three tasks
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement