python 在不同CPU上同时运行多个程序
2024-09-05 21:49:16
In [24]: import os
In [25]: import numpy as np
In [26]: from multiprocessing import Process
In [27]: class MyProc(Process):
...: def __init__(self, num):
...: self.num = num
...: super().__init__()
...:
...: def run(self):
...: print(f'Process {self.num} starting...PID {os.getpid()}')
...: np.random.seed(self.num)
...: total = np.sum([np.random.randint(10_000)
for _ in range(10_000_000)])
...: print(f'Total sum = {total}')
...:
In [28]: procs = [MyProc(i) for i in range(2)]
In [29]: for p in procs:
...: p.start()
...:
Process 0 starting...PID 92402
Process 1 starting...PID 92403
In [30]: for p in procs:
...: p.join()
...:
Total sum = 50003085304
Total sum = 49988200971
最新文章
- Material Design兼容包的使用
- JS二维数组排序组合
- linux关于文件的那些事儿
- CLR
- SQLHelper、DBUtil终极封装
- ACM题目————列变位法解密
- easyui tabs内容panel自适应窗体宽度方法
- execl csv导出
- C++ 常见容器
- Ntaub表单开发入门系列 (一)
- SG函数和SG定理
- 实用小技巧(一):UIScrollView中上下左右滚动方向的判断
- Python ORM框架之SQLAlchemy
- 模块import,from ..import...
- EL表达式和标签
- UVALive 6916 Punching Robot dp
- sql分组排序取top
- Android NDK开发-2-环境搭建
- Malformed \uxxxx encoding
- Download/Attach source-code/java-docs with maven dependencies