Skip to content

Commit dec19e1

Browse files
committed
doc
1 parent e2d62b5 commit dec19e1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
Examples of Python asyncio.subprocess with FFmpeg and also traditional synchronous processes.
66

7+
## Coroutine vs Threads vs processes
8+
9+
For computationally bound programs, multiple processes is often a good choice. Try:
10+
11+
```sh
12+
python demo.py -h
13+
```
14+
715
## FFprobe
816

917
Both synchronous (traditional for loop) and asynchronous pipeline are demonstrated.
@@ -25,7 +33,6 @@ However, the rationale employed is that the FFprobe task is overall lightweight,
2533
If the FFprobe task was in an asyncio.gather() algorithm, resource utilization could get too high.
2634
Thus we have a "win-win" by using asyncio generator for FFprobe--the throttling comes implicitly from other parts of the pipeline.
2735

28-
2936
### Threading
3037

3138
Even though coroutines are more efficient in many applications, the syntax of `concurrent.futures.ThreadPoolExecutor` is perhaps the simplest possible way to spawn independent processes in a controlled fashion.
@@ -45,7 +52,7 @@ Build by
4552

4653
```sh
4754
meson build
48-
meson test -C build
55+
meson compile -C build
4956
```
5057

5158
run like

play_thread.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#!/usr/bin/env python3
2+
"""
3+
ProcessPoolExecutor would work similarly,
4+
but is not needed here since all computation is done in the external program.
5+
"""
6+
27
from pathlib import Path
38
import subprocess
49
from argparse import ArgumentParser

0 commit comments

Comments
 (0)