forked from nedbat/coveragepy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes nedbat#9.
- Loading branch information
Showing
11 changed files
with
578 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ The manual | |
streams | ||
networking | ||
threads | ||
subprocesses | ||
fileio | ||
signals | ||
testing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
Using subprocesses | ||
================== | ||
|
||
AnyIO allows you to run arbitrary executables in subprocesses, either as a one-shot call or by | ||
opening a process handle for you that gives you more control over the subprocess. | ||
|
||
You can either give the command as a string, in which case it is passed to your default shell | ||
(equivalent to ``shell=True`` in :func:`subprocess.run`), or as a sequence of strings | ||
(``shell=False``) in which the executable is the first item in the sequence and the rest are | ||
arguments passed to it. | ||
|
||
.. note:: The subprocess facilities provided by AnyIO do not include a way to execute arbitrary | ||
Python code like the :mod:`multiprocessing` module does, but they can be used as | ||
building blocks for such a feature. | ||
|
||
Running one-shot commands | ||
------------------------- | ||
|
||
To run an external command with one call, use :func:`~anyio.run_process`:: | ||
|
||
from anyio import run_process, run | ||
|
||
|
||
async def main(): | ||
result = await run_process('/usr/bin/ps') | ||
print(result.stdout.decode()) | ||
|
||
run(main) | ||
|
||
The snippet above runs the ``ps`` command within a shell (. To run it directly:: | ||
|
||
from anyio import run_process, run | ||
|
||
|
||
async def main(): | ||
result = await run_process(['/usr/bin/ps']) | ||
print(result.stdout.decode()) | ||
|
||
run(main) | ||
|
||
Working with processes | ||
---------------------- | ||
|
||
When you have more complex requirements for your interaction with subprocesses, you can launch one | ||
with :func:`~anyio.open_process`:: | ||
|
||
from anyio import open_process, run | ||
from anyio.streams.text import TextReceiveStream | ||
|
||
|
||
async def main(): | ||
async with await open_process(['/usr/bin/ps']) as process: | ||
for text in TextReceiveStream(process.stdout): | ||
print(text) | ||
|
||
run(main) | ||
|
||
See the API documentation of :class:`~anyio.abc.subprocesses.Process` for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.