Files
wiki/thread-python/README.md
2025-02-22 10:46:48 +00:00

13 lines
352 B
Markdown

```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)
```