/
__init__.py
67 lines (50 loc) · 1.56 KB
/
__init__.py
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
63
64
65
66
67
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
---------------------------------
Asynchronous Compatibility Module
---------------------------------
Notify: You should run ``pip install "kipp[aio]"`` to install requirements.
Examples:
Write your own coroutine:
::
from kipp.aio import (
get_event_loop, coroutine2, sleep,
run_until_complete, wrapper, wait,
set_aio_n_workers
)
@coroutine2
def sub_task():
yield sleep(0.5)
return_in_coroutine('subtask ok')
@coroutine2
def demo():
r = yield sub_task
assert r == 'subtask ok'
yield sleep(0.5)
return_in_coroutine('ok')
future = demo()
# wait future done
run_until_complete(future)
# get the result
result = future.result()
assert result == 'ok'
# Run many tasks
futures = [demo() for _ in range(10)]
gathered_future = wait(futures)
run_until_complete(gathered_future)
assert([r=='ok' for r in gathered_future.result()])
"""
from __future__ import unicode_literals
from kipp.libs.aio import (
Future, sleep, coroutine,
get_event_loop, run_until_complete,
return_in_coroutine,
Semaphore, Event, MultiEvent,Condition,
Queue, wait)
from .base import (
wrapper, set_aio_n_workers, coroutine2,
thread_executor as aio_internal_thread_executor,
as_completed,)
from .sqlhelper import SqlHelper
from .http import HTTPSessionClient, get_http_client_session