-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
36 lines (26 loc) · 783 Bytes
/
test.py
File metadata and controls
36 lines (26 loc) · 783 Bytes
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
import logging
import time
import core
logging.basicConfig(
format="%(name)s-%(asctime)s-[%(levelname)s]: %(message)s",
level=logging.INFO,
)
LOGGER = logging.getLogger(__name__)
def test(x: int) -> None:
LOGGER.info("The test function %d start running." % x)
time.sleep(2)
LOGGER.info("The test function %d has running finished." % x)
return "function %d return." % x
def cb(callback_task: core.ThreadTask) -> None:
LOGGER.info(callback_task.get_result())
pool = core.SimpleThreadPool(threads=32)
for i in range(64):
task = pool.submit(test, i)
task.add_callback(cb)
# wait timeout 2 seconds.
# pool.wait(2)
pool.wait()
print("main: wait release")
pool.shutdown()
# pool.shutdown(1)
print("main: pool has been shutdown successfully.")