出处/From https://www.quora.com/If-you-run-Python-under-a-dual-core-CPU-then-can-you-run-two-Python-programs-at-once-one-that-utilizes-1-core-and-the-other-utilizing-the-other-core

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

最新文章

  1. Material Design兼容包的使用
  2. JS二维数组排序组合
  3. linux关于文件的那些事儿
  4. CLR
  5. SQLHelper、DBUtil终极封装
  6. ACM题目————列变位法解密
  7. easyui tabs内容panel自适应窗体宽度方法
  8. execl csv导出
  9. C++ 常见容器
  10. Ntaub表单开发入门系列 (一)
  11. SG函数和SG定理
  12. 实用小技巧(一):UIScrollView中上下左右滚动方向的判断
  13. Python ORM框架之SQLAlchemy
  14. 模块import,from ..import...
  15. EL表达式和标签
  16. UVALive 6916 Punching Robot dp
  17. sql分组排序取top
  18. Android NDK开发-2-环境搭建
  19. Malformed \uxxxx encoding
  20. Download/Attach source-code/java-docs with maven dependencies

热门文章

  1. day58—JavaScript面向对象(一)
  2. 从 2017 OpenStack Days China 看国内云计算的发展现状
  3. Components controls 区别
  4. linux优化
  5. linux下升级php5.4到php5.6
  6. TensorFlow学习笔记13-循环、递归神经网络
  7. hackinglab 脚本关 writeup
  8. bash shell for循环
  9. 回溯---Permutations II
  10. Log4Net 之将日志记录到数据库的后台实现 (二)