Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_main.py
More file actions
Latest commit
62 lines (47 loc) · 1.76 KB
/
Copy pathsync_main.py
File metadata and controls
62 lines (47 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
Run this example with:
python -m github.sync_main
This is an example of using Effect in a normal program that uses
synchronous/blocking functions to do I/O.
This code has these responsibilities:
- set up a dispatcher that knows how to find performers for all intents
used in this application. The application uses ReadLine, HTTPRequest, and
ParallelEffects.
- use :func:`effect.sync_perform` to perform an effect, which returns the
result of the effect (or raises an exception it it failed).
"""
from __future__ importprint_function
fromfunctoolsimportpartial
frommultiprocessing.poolimportThreadPool
fromeffectimportComposedDispatcher, ParallelEffects, TypeDispatcher, sync_perform
fromeffect.threadsimportperform_parallel_with_pool
fromehttp.http_intentimportHTTPRequest
fromehttp.sync_httpimportperform_request_requests
fromreadline_intentimportReadLine, perform_readline_stdin
from .coreimportmain_effect
defget_dispatcher():
"""
Create a dispatcher that can find performers for :obj:`ReadLine`,
:obj:`HTTPRequest`, and :obj:`ParallelEffects`. There's a built-in
performer for ParallelEffects that uses a multiprocessing ThreadPool,
:func:`effect.perform_parallel_with_pool`.
"""
my_pool=ThreadPool()
pool_performer=partial(perform_parallel_with_pool, my_pool)
returnComposedDispatcher(
[
TypeDispatcher(
{
ReadLine: perform_readline_stdin,
HTTPRequest: perform_request_requests,
ParallelEffects: pool_performer,
}
)
]
)
defmain():
dispatcher=get_dispatcher()
eff=main_effect()
print(sync_perform(dispatcher, eff))
if__name__=="__main__":
main()