Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #55438
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'interpreter': 0.05; 'debug': 0.07; 'high-level': 0.09; 'properly.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:script': 0.09; 'wrong,': 0.09; 'python': 0.11; 'assume': 0.14; 'thread': 0.14; 'downside': 0.16; 'exist.': 0.16; 'headaches': 0.16; 'incremented': 0.16; 'interacting,': 0.16; 'objects.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'roy': 0.16; 'sorts': 0.16; 'subject:versus': 0.16; 'thread,': 0.16; 'unsafe': 0.16; 'language': 0.16; 'wrote:': 0.18; 'library': 0.18; 'variable': 0.18; 'module': 0.19; 'written': 0.21; 'memory': 0.22; 'handles': 0.22; 'header:User-Agent:1': 0.23; 'equivalent': 0.26; 'header:X -Complaints-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'possibility': 0.29; 'raise': 0.29; 'code': 0.31; 'another': 0.32; '(i.e.': 0.33; 'continuing': 0.33; 'fri,': 0.33; 'third': 0.33; 'could': 0.34; 'one,': 0.35; 'but': 0.35; 'really': 0.36; 'charset:us-ascii': 0.36; "i'll": 0.36; 'two': 0.37; 'problems': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'problems.': 0.60; 'simple': 0.61; "you're": 0.61; 'guarantee': 0.63; 'show': 0.63; 'more': 0.64; 'different': 0.65; 'smith': 0.68; 'sharing': 0.69; 'risk': 0.72; 'allocation': 0.74; 'counts': 0.83; 'presumably': 0.84; 'safe.': 0.84; 'careful': 0.91; 'hand,': 0.93; '2013': 0.98 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dave Angel <davea@davea.name> |
| Subject | Re: Multiple scripts versus single multi-threaded script |
| Date | Thu, 3 Oct 2013 18:40:13 +0000 (UTC) |
| References | <f01b2e7a-9fc7-4138-bb6e-447d31179f2d@googlegroups.com> <roy-451497.12415103102013@news.panix.com> <CAPTjJmrtvJ4OCA34txYQHfxGqHdEL9z4B-wsh0mrtFLcRWjtFA@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=US-ASCII |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | 174.32.174.31 |
| User-Agent | XPN/1.2.6 (Street Spirit ; Linux) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.692.1380825636.18130.python-list@python.org> (permalink) |
| Lines | 45 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1380825636 news.xs4all.nl 15946 [2001:888:2000:d::a6]:44429 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:55438 |
Show key headers only | View raw
On 3/10/2013 12:50, Chris Angelico wrote:
> On Fri, Oct 4, 2013 at 2:41 AM, Roy Smith <roy@panix.com> wrote:
>> The downside to threads is that all of of this sharing makes them much
>> more complicated to use properly. You have to be aware of how all the
>> threads are interacting, and mediate access to shared resources. If you
>> do that wrong, you get memory corruption, deadlocks, and all sorts of
>> (extremely) difficult to debug problems. A lot of the really hairy
>> problems (i.e. things like one thread continuing to use memory which
>> another thread has freed) are solved by using a high-level language like
>> Python which handles all the memory allocation for you, but you can
>> still get deadlocks and data corruption.
>
> With CPython, you don't have any headaches like that; you have one
> very simple protection, a Global Interpreter Lock (GIL), which
> guarantees that no two threads will execute Python code
> simultaneously. No corruption, no deadlocks, no hairy problems.
>
> ChrisA
The GIL takes care of the gut-level interpreter issues like reference
counts for shared objects. But it does not avoid deadlock or hairy
problems. I'll just show one, trivial, problem, but many others exist.
If two threads process the same global variable as follows,
myglobal = myglobal + 1
Then you have no guarantee that the value will really get incremented
twice. Presumably there's a mutex/critsection function in the threading
module that can make this safe, but once you use it in two different
places, you raise the possibility of deadlock.
On the other hand, if you're careful to have the thread use only data
that is unique to that thread, then it would seem to be safe. However,
you still have the same risk if you call some library that wasn't
written to be thread safe. I'll assume that print() and suchlike are
safe, but some third party library could well use the equivalent of a
global variable in an unsafe way.
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Multiple scripts versus single multi-threaded script JL <lightaiyee@gmail.com> - 2013-10-03 09:01 -0700
Re: Multiple scripts versus single multi-threaded script Roy Smith <roy@panix.com> - 2013-10-03 12:41 -0400
Re: Multiple scripts versus single multi-threaded script Chris Angelico <rosuav@gmail.com> - 2013-10-04 02:50 +1000
Re: Multiple scripts versus single multi-threaded script Roy Smith <roy@panix.com> - 2013-10-03 14:28 -0400
Re: Multiple scripts versus single multi-threaded script Chris Angelico <rosuav@gmail.com> - 2013-10-04 04:36 +1000
Re: Multiple scripts versus single multi-threaded script Roy Smith <roy@panix.com> - 2013-10-03 15:53 -0400
Re: Multiple scripts versus single multi-threaded script Chris Angelico <rosuav@gmail.com> - 2013-10-04 08:22 +1000
Re: Multiple scripts versus single multi-threaded script Dave Angel <davea@davea.name> - 2013-10-03 18:40 +0000
Re: Multiple scripts versus single multi-threaded script Jeremy Sanders <jeremy@jeremysanders.net> - 2013-10-04 10:02 +0200
Re: Multiple scripts versus single multi-threaded script Grant Edwards <invalid@invalid.invalid> - 2013-10-04 16:38 +0000
Re: Multiple scripts versus single multi-threaded script Chris Angelico <rosuav@gmail.com> - 2013-10-04 02:42 +1000
csiph-web