Add thread-python/README.md
This commit is contained in:
13
thread-python/README.md
Normal file
13
thread-python/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
```python
|
||||
def worker(x):
|
||||
__import__('time').sleep(1)
|
||||
print(x, end=' ')
|
||||
return x ** 3
|
||||
|
||||
with __import__('concurrent').futures.ThreadPoolExecutor(64) as T:
|
||||
y = list(T.map(worker, range(100)))
|
||||
# 64개 worker로 100개의 1초 소요되는 작업: 2초후 종료
|
||||
|
||||
# x는 순서대로 호출 안되지만 y는 순서대로 나옴
|
||||
print(y)
|
||||
```
|
||||
Reference in New Issue
Block a user