python多线程编程
2017-03-06 20:37
274 查看
python多线程编程架构
import Queue import threading import subprocess q = Queue.Queue() for i in range(30): #put 30 tasks in the queue q.put(i) def worker(): #replace worker with you want to parallel preprocess while True: item = q.get() #execute a task: call a shell program and wait until it completes subprocess.call("echo "+str(item), shell=True) q.task_done() cpus=numofyourcpu #detect number of cores print("Creating %d threads" % cpus) for i in range(cpus): t = threading.Thread(target=worker) t.daemon = True t.start() q.join() #block until all tasks are done
相关文章推荐
- zt:python多线程编程
- Python多线程编程
- python多线程编程(2): 线程的创建、启动、挂起和退出
- python多线程编程(6): 队列同步
- Python多线程编程(2): 线程的创建、启动、挂起和退出
- python多线程编程(7):线程间通信
- python多线程编程(3): 使用互斥锁同步线程
- python 多线程编程(三)
- python多线程编程(5): 条件变量同步
- Python多线程编程
- Python多线程编程的两种方式
- python 多线程编程并不能真正利用多核的CPU
- python多线程编程(1): python对多线程的支持
- Python多线程编程
- Python多线程编程
- Python多线程编程
- Python多线程编程
- python多线程编程(4): 死锁和可重入锁
- Python多线程编程(1): python对多线程的支持
- Python多线程编程(3): 使用互斥锁同步线程