python 线程池中跑两个线程的demo
时间: 2023-10-24 17:17:03 浏览: 156
好的,请见下方代码:
```python
import concurrent.futures
import time
def say_hello(name):
print(f"Hello, {name}")
time.sleep(1) # 模拟耗时操作
print(f"Goodbye, {name}")
if __name__ == '__main__':
pool = concurrent.futures.ThreadPoolExecutor(max_workers=2) # 线程池最多维护两个线程
pool.submit(say_hello, "John")
pool.submit(say_hello, "Alice")
```
祝您使用愉快!请问还有其他需要帮助的问题吗?
阅读全文