多线程概念 [英] multithreading concept

查看:83
本文介绍了多线程概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计,


Python也受到称赞 - 我也是。但有一次它失败了。它无法使用
表现为真正的多线程应用程序。这意味着在SMP中并行使用所有

CPU有效地保持了Python的梦想。

程序员。


讨论主题说它是由于GIL - 全球翻译锁定。但是没有人提出任何替代方案,除了像在C中编码它的代码是/ b $ b b这样的建议。和POSH( http://poshmodule.sf.net) 。还有其他任何方式我们可以使用实际意义上的Python程序真的是多线程的。


Moin

Hi Folks,

Python is praised about - me too. But at one instance it fails. It fails to
behave as a true multi-threaded application. That means utilizing all the
CPUs parallely in the SMP efficiently stays as a dream for a Python
Programmer.

Discussion threads say its due to GIL - global interpreter lock. But nobody
has mentioned any alternative to that apart from suggestions like "Code it
in C" and POSH (http://poshmodule.sf.net). Is there any other way we can
make Python programs really multithreaded in real sense.

Moin

推荐答案

2月7日凌晨1点53分,S.Mohideen < m ... @ blackhole.labs.rootshell.ws>

写道:
On Feb 7, 1:53 am, "S.Mohideen" <m...@blackhole.labs.rootshell.ws>
wrote:

嗨伙计,


Python也受到称赞 - 我也是。但有一次它失败了。它无法使用
表现为真正的多线程应用程序。这意味着在SMP中并行使用所有

CPU有效地保持了Python的梦想。

程序员。


讨论主题说它是由于GIL - 全球翻译锁定。但是没有人提出任何替代方案,除了像在C中编码它的代码是/ b $ b b这样的建议。和POSH( http://poshmodule.sf.net) 。还有其他任何方式我们可以使用实际意义上的Python程序实现多线程。


Moin
Hi Folks,

Python is praised about - me too. But at one instance it fails. It fails to
behave as a true multi-threaded application. That means utilizing all the
CPUs parallely in the SMP efficiently stays as a dream for a Python
Programmer.

Discussion threads say its due to GIL - global interpreter lock. But nobody
has mentioned any alternative to that apart from suggestions like "Code it
in C" and POSH (http://poshmodule.sf.net). Is there any other way we can
make Python programs really multithreaded in real sense.

Moin



实际上他们是*很多*更多的建议&讨论有待发现。

我自己走向并行处理很难。如果你认为这很容易,那就是你的幸运或理论。虽然为了完整起见将线程==本机线程很好,但是我很高兴,我很高兴能够运行并发通信进程,就像我的

机器操作系统帮助我查看流程发生了什么,并且

停止流程践踏共享数据。


-Paddy。

Actually their are a *lot* more suggestions & discussions to be found.
I myself move towards the "parallel processing is difficult. If you
think it''s easy then your either lucky or theorising. Whilst it would
be nice to have threads==native threads for completeness sake, I''m
quit happy to run concurrent communicating processes, as on my
machines the OS helps me to see what''s happening to the processes, and
stops processes trampling over shared data".

-Paddy.


2月7日凌晨2:53,S.Mohideen < m ... @ blackhole.labs.rootshell.ws>

写道:
On Feb 7, 2:53 am, "S.Mohideen" <m...@blackhole.labs.rootshell.ws>
wrote:

Python也受到称赞 - 我也是。但有一次它失败了。它无法使用
表现为真正的多线程应用程序。这意味着在SMP中并行使用所有的&b
CPU可以有效地成为Python的梦想。
程序员。
Python is praised about - me too. But at one instance it fails. It fails to
behave as a true multi-threaded application. That means utilizing all the
CPUs parallely in the SMP efficiently stays as a dream for a Python
Programmer.



此前已经讨论过死亡。 Win32线程和pthreads

(这是Python通常使用的,取决于平台)

旨在大多数时间保持空闲状态。因此,它们不是一个利用多个CPU的功能的工具,而是使某些类型的编程任务更容易编程(即非阻塞I / O,

响应式用户界面)。在这种情况下,GIL不是问题。如果线程

大部分时间都处于空闲状态,那么GIL不会造成伤害。


如果你想利用多个CPU的计算能力,你可以/>
应该使用多个进程而不是线程。在Python上,由于GIL,这是强制性的
。在任何其他语言中,它高度推荐
。并行多处理(MPI)的de-factor标准

使用多个进程,即使在SMP上也是如此。任何有严重意图的人使用多个处理器进行并行计算都需要使用

多个进程和快速IPC - 而不是多线程,共享内存

和同步对象 - 即使语言是普通的C.使用

多个线程,浪费了大量时间进行上下文切换和

预订线程同步。另外,模糊和

通常很难识别错误。


MPI(mpi4py)的Python绑定和类似的纯Python

项目(并行Python)将负责

你的所有这些细节。

This has been discussed to death before. Win32 threads and pthreads
(which is what Python normally uses, depending on the platform) are
designed to stay idle most of the time. They are therefore not a tool
for utilizing the power of multiple CPUs, but rather make certain kind
of programming tasks easier to program (i.e. non-blocking I/O,
responsive UIs). The GIL is not a problem in this context. If threads
stay idle most of the time, the GIL does not harm.

If you want to utilize the computing power of multiple CPUs, you
should use multiple processes instead of threads. On Python this is
mandatory due to the GIL. In any other language it it highly
recommended. The de-factor standard for parallel multiprocessing (MPI)
uses multiple processes, even on SMPs. Anyone with serious intentions
of using multiple processors for parallel computing should use
multiple processes and fast IPC - not multiple threads, shared memory
and synchronization objects - even if the language is plain C. With
multiple threads, a lot of time is wasted doing context switches and
book keeping for the thread synchronization. In addition, obscure and
often very difficult to identify bugs are introduced.

There are a Python binding for MPI (mpi4py) and a similar pure Python
project (Parallel Python) that will take care of all these details for
you.


讨论主题说它是由于GIL - 全局解释器锁定。但是没有人提出任何替代方案,除了像在C中编码它的代码是/ b $ b b这样的建议。和POSH( http://poshmodule.sf.net) 。还有其他任何方式我们可以使用实际意义上的Python程序实现多线程。
Discussion threads say its due to GIL - global interpreter lock. But nobody
has mentioned any alternative to that apart from suggestions like "Code it
in C" and POSH (http://poshmodule.sf.net). Is there any other way we can
make Python programs really multithreaded in real sense.



如上所述,使用MPI或Parallel Python。到目前为止MPI已经成熟了,但对于pythoneer来说,并行Python可能更容易。

多线程有不同的用途。



2月7日,02:53,S.Mohideen < m ... @ blackhole.labs.rootshell.ws>

写道:
On 7 Feb, 02:53, "S.Mohideen" <m...@blackhole.labs.rootshell.ws>
wrote:

>

Python受到了赞扬 - 我也是。但有一次它失败了。它无法使用
表现为真正的多线程应用程序。这意味着在SMP中并行使用所有的&b
CPU可以有效地成为Python的梦想。
程序员。
>
Python is praised about - me too. But at one instance it fails. It fails to
behave as a true multi-threaded application. That means utilizing all the
CPUs parallely in the SMP efficiently stays as a dream for a Python
Programmer.



查看Python Wiki以获取有关并行处理的信息

with Python:

http://wiki.python.org/moin/ParallelProcessing


纯CPython代码可能无法通过使用线程仅使用多个CPU

(Jython和IronPython不同,

虽然) ,但是使用SMP系统中的所有CPU或内核并不仅仅是梦想,因为上页列出的许多项目都证明了这一点。


Paul

Take a look at the Python Wiki for information on parallel processing
with Python:

http://wiki.python.org/moin/ParallelProcessing

Pure CPython code may not be able to use more than one CPU merely
through the use of threads (Jython and IronPython are different,
though), but using all the CPUs or cores in an SMP system is not
exactly a mere dream, as many of the projects listed on the above page
demonstrate.

Paul


这篇关于多线程概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆