Skip to content

Commit a21780a

Browse files
author
czheo
committed
update README.md
1 parent 2b1de5a commit a21780a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,27 @@ p(20)
6767
# returns 36
6868
```
6969

70-
### pipe with thread/process and multiprocessing
70+
### pipe with parallelism
7171

72-
You can have a function running in a seperate thread with pipe. Just put it in a `[]` or more explicitly `t[]`.
72+
By default, pipe works with green threads which is based on event loop.
7373

74-
Because of the notorious GIL(Global Interpret Lock) of Python, people may want processes instead of threads. Just put a function in `p[]`.
74+
You can have a function running in a seperate green thread with pipe. Just put it in a `[]` or more explicitly `g[]`. Multithreads or multiprocesses are also available.
7575

7676
``` python
77-
from syntax_sugar import thread_syntax as t, process_syntax as p
77+
from syntax_sugar import (green_thread_syntax as g,
78+
thread_syntax as t,
79+
process_syntax as p)
7880

79-
pipe(10) | [print] | END # print run in a thread
81+
pipe(10) | [print] | END # print run in a green thread
82+
pipe(10) | g[print] | END # print run in a green thread
8083
pipe(10) | t[print] | END # print run in a thread
8184
pipe(10) | p[print] | END # print run in a process
8285
```
8386

84-
What makes this syntax good is that you can specify how many threads you want to spawn, by doing `[function] * n` where `n` is the number of threads.
87+
What makes this syntax good is that you can specify how many green threads you want to spawn, by doing `[function] * n` where `n` is the number of green threads.
8588

8689
``` python
87-
pipe([1,2,3,4,5]) | [print] * 3 | END # print will run in a ThreadPool of size 3
90+
pipe([1,2,3,4,5]) | [print] * 3 | END # print will run in a GreenThreadPool of size 3
8891
```
8992

9093
Here is an example of requesting a list of urls in parallel
@@ -93,7 +96,7 @@ Here is an example of requesting a list of urls in parallel
9396
import requests
9497
(pipe(['google', 'twitter', 'yahoo', 'facebook', 'github'])
9598
| each(lambda name: 'http://' + name + '.com')
96-
| [requests.get] * 3 # !! `requests.get` runs in a ThreadPool of size 3
99+
| [requests.get] * 3 # !! `requests.get` runs in a GreenThreadPool of size 3
97100
| each(lambda resp: (resp.url, resp.headers.get('Server')))
98101
| list
99102
| END)

0 commit comments

Comments
 (0)