asyncio.create_subprocess_exec
Prev: asyncio.create_eager_task_factory | Up: asyncio | Next: asyncio.create_subprocess_shell
Rel: asyncio.AbstractEventLoop, asyncio.AbstractServer, asyncio.all_tasks, asyncio.as_completed
Ref: docs.python.org — asyncio.create_subprocess_exec
Tags: #public #python3 #stdlib #asyncio
Import
import asyncio
from asyncio import create_subprocess_exec
Signature & Overview
asyncio.create_subprocess_exec(program, *args, stdin=None, stdout=None, stderr=None, limit=65536, **kwds)
asyncio.create_subprocess_exec() function.
Usage
import asyncio
import sys
async def main():
proc = await asyncio.create_subprocess_exec(
sys.executable, "-c", "print('async-ok')",
stdout=asyncio.subprocess.PIPE,
)
out, _ = await proc.communicate()
assert proc.returncode == 0 and out.decode().strip() == "async-ok"
asyncio.run(main())
Gotchas
- Safer than
create_subprocess_shell: Passes arguments directly without shell parsing. - Always await
proc.communicate()orproc.wait(): Prevents zombie processes.
REPL Inspect
from asyncio import create_subprocess_exec
help(create_subprocess_exec)
Linked from
Related notes
- tuts/python3/stdlib_module/asyncio/create_eager_task_factory Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/create_subprocess_shell Linked here; links to this page; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/asyncio/AbstractEventLoop Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/AbstractServer Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/all_tasks Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/as_completed Linked here; shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/Barrier shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/BaseEventLoop shared tags: #asyncio, #stdlib
- tuts/python3/stdlib_module/asyncio/BaseProtocol shared tags: #asyncio, #stdlib