Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5011784
  • 博文数量: 921
  • 博客积分: 16037
  • 博客等级: 上将
  • 技术积分: 8469
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-05 02:08
文章分类

全部博文(921)

文章存档

2020年(1)

2019年(3)

2018年(3)

2017年(6)

2016年(47)

2015年(72)

2014年(25)

2013年(72)

2012年(125)

2011年(182)

2010年(42)

2009年(14)

2008年(85)

2007年(89)

2006年(155)

分类: Python/Ruby

2012-04-09 16:02:20

Python2.6正好在10.1发布,我还没有仔细看完就迫不及待地写这个介绍给大家,有太多令人激动的新改进。2.6是向Python3.0(Python3000)过渡的版本,Python3000是一个新的台阶,不跟python2.x序列兼容。我仔细地看了一下新增加的处理多进程的包组Multiprocessing(PEP 371),这是python为利用渐成主流的M3系统平台提供的服务而精心打造的武器。官方文档说是“Process-based ‘Threading’interface”:(注:M3平台是我的独出心裁,就是指多核、多处理器和多计算机系统Multicore、Multi CPU、Multi computers,我叫他M3系统编程,把本地的多核心多处理器与远程多计算机放在同一个框架下面来考虑有许多优势,例如multiprocessing.Manager就是这样做的)
  • multiprocessing is a package that supports spawning processes using an API similar to the module. The multiprocessing package offers both local and remote concurrency, effectively side-stepping the by using subprocesses instead of threads. Due to this, the multiprocessing module allows the programmer to fully leverage multiple processors on a given machine. It runs on both Unix and Windows.


Python处理并行计算的两个主要工具是Threading和Multiprocessing,像上面的文档说得multiprocessing使用类似Threading的API来创建和管理进程(不是线程!)。令人振奋的是multiprocessing提供本地和远程的同步处理方法,能让程序员充分利用M3提供的强大计算能力,而不是让它们停留在广告效应上,不再是“银样蜡枪头,中看不中用”了。多线程技术是我们比较熟悉的,但是多线程不能利用多核心和多处理器的运算能力。在分布式并行处理方面,python是捷足先登引领潮流了。这绝不是偶然的,在操作系统导师主持的最早分布式操作系统Amoeba工作的时候,为它开发系统管理程序设计开发的,所以python具有优良的血统,是专门为分布式系统开发的工具,我个人感觉在分布式并行处理方面python要领先于java,更不用说是C#了。当然,偏好有的时候就是偏见!Python2.6也就是Python3000,有效地解决了(side-stepping)“全局锁GIL”的问题,我们来看上的说法:
  • The main issue of using CPython on a computer is the presence of a on each CPython interpreter process, which effectively disables concurrent Python threads within one process. To be truly concurrent in multiprocessor environment, separate CPython interpreter processes have to be run, which makes establishing communication between them a difficult task. There is constant discussion whether to remove the GIL from CPython.


现在把分布式并行系统编程的界面和系统调用封装在一起了,简单介绍如下:
  1. multiprocessing.Process创建新的进程,参数target=f,就把一个名字f的子进程创建出来了;
  2. multiprocessing.Queue
  3. multiprocessing.Pipe
  4. multiprocessing.Pool用来管理创建的多个子进程让它们协调工作
  5. multiprocessing.Manager管理在远程服务器上创建的子进程,封装了Lock和RLock锁和信号Semophore,这样不必单独处理并行问题了。
等等。如果这里的朋友有感兴趣的,我会再详细介绍。
阅读(1630) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

ljloo12012-04-10 21:35:39

很多错

无色T恤2012-04-10 02:20:13

多线程比较简单还是……