Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61685 > unrolled thread

Re: Threading In Python

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2013-12-12 01:41 -0700
Last post2013-12-12 01:41 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Threading In Python Ian Kelly <ian.g.kelly@gmail.com> - 2013-12-12 01:41 -0700

#61685 — Re: Threading In Python

FromIan Kelly <ian.g.kelly@gmail.com>
Date2013-12-12 01:41 -0700
SubjectRe: Threading In Python
Message-ID<mailman.3975.1386837754.18130.python-list@python.org>
On Thu, Dec 12, 2013 at 1:08 AM, marcinmltd <marcinmltd@gmail.com> wrote:
> Adding subject to the message.
> Hello,
>
> I'm big fan of multiprocessing module, but recently I started looking at
> threading in Python more closely and got couple of questions I hope You can
> help me with:
>
> 1. When I run two or more threads in my python process are they really run
> concurrently on mulicore machine?

No.  The GIL allows the Python interpreter to run in only thread at a time.

> 2. Browsing through documentation it looks like python interpreter protects
> its sensitive states by using GIL. Can you guys list situations when this
> happens?

Any time Python code is being run, the GIL is held.  C extensions have
the option to release the GIL for long-running operations (e.g.
waiting on a network socket), but they are not permitted to work with
Python objects while the GIL is released.

> 2. What would be general advice from python experts on when to use threadng
> and when switch to multliprocessing in python? Is the decision still
> influenced by how often we need to comunicate between the tasks as it's in
> C\C++?

Generally speaking, use threading for programs that are IO-bound
(where there would be little concurrency anyway) and multiprocessing
for programs that are CPU-bound.  Communication between processes is
more expensive than communication between threads, so that could be an
important criterion.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web