Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45577
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| 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; '(even': 0.05; 'cpython': 0.05; 'interpreter': 0.05; 'that?': 0.05; 'cache': 0.07; 'context': 0.07; 'interpreter.': 0.07; 'subject:help': 0.08; 'assuming': 0.09; 'back.': 0.09; 'here?': 0.09; 'interpreted': 0.09; 'runtime': 0.09; 'stack,': 0.09; 'python': 0.11; 'thread': 0.14; 'windows': 0.15; '"every': 0.16; '(yes': 0.16; 'blocked': 0.16; 'bytecode': 0.16; 'core.': 0.16; 'distinct': 0.16; 'processor,': 0.16; 'received:74.208.4.195': 0.16; 'repetition': 0.16; 'thread,': 0.16; 'threads,': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'trying': 0.19; 'stack': 0.19; 'seems': 0.21; '>>>': 0.22; 'separate': 0.22; 'header:User-Agent:1': 0.23; "aren't": 0.24; 'processor': 0.24; 'helpful': 0.24; 'versions': 0.24; 'sort': 0.25; 'equivalent': 0.26; 'switch': 0.26; 'gets': 0.27; 'header :In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; "doesn't": 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; 'overhead': 0.31; 'linux': 0.33; 'running': 0.33; 'core': 0.34; 'subject:with': 0.35; "can't": 0.35; 'common': 0.35; 'knows': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'done,': 0.36; 'scheduled': 0.36; 'done': 0.36; "didn't": 0.36; 'so,': 0.37; 'level': 0.37; 'implement': 0.38; 'ahead': 0.38; 'mapping': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'track': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'easy': 0.60; 'catch': 0.60; 'lower': 0.61; 'new': 0.61; "you're": 0.61; 'making': 0.63; 'real': 0.63; 'map': 0.64; 'more': 0.64; 'different': 0.65; 'due': 0.66; 'between': 0.67; 'received:74.208': 0.68; 'default': 0.69; '100': 0.79; 'transfer': 0.82; 'lightweight': 0.84; 'misses': 0.84; 'overall,': 0.84; 'carlos': 0.91; 'same,': 0.91; 'hand,': 0.93; '2013': 0.98 |
| Date | Sun, 19 May 2013 21:04:42 -0400 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Please help with Threading |
| References | <7baacf5a-0c50-4935-ad5b-148c208d759b@googlegroups.com> <13lfp8lds6e2e41rtsnvqimcb6inu7p28o@invalid.netcom.com> <BLU176-W444B989132C26C3A305CB7D7AE0@phx.gbl> <CAPTjJmoJExzBAg7LXodAJVLCe=dpUqOqeUjzXLCWWzxbqz=vEQ@mail.gmail.com> <mghip81l8gs30fjvkdfdp5h9fn622habdg@invalid.netcom.com> |
| In-Reply-To | <mghip81l8gs30fjvkdfdp5h9fn622habdg@invalid.netcom.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:XBD8UDgo/I7xn3SGoIwXwbMwKise0eKxbbEGwXU3kK3 XGUTZlWMx2vQFlEi6DWpR5xLf9hcW4/R2fv8LcRrDje//D7y56 mUYqW3rucnvjjpdlk4cL4++LMZABkGKDorT46wWY1CBLMj6BCR UmWpEwcLXjMYab6yR7zwfQFHqIkBd46aQnF/JMFn9zzAOXPXJg scrwrShFQiysKVvf3BBIOKl9NqyG3+Poox1KpBdUTFEDMYXaY7 AjMxF8AJvn1OXAT4fhyXRcbkqoCY2KsxN0H4ZUDZ2xO+D4yg4N RHp2Apo7W2ObkkKW6BwmAeWt3/IXXP2LbAM1TSbB88p61U7NBe mLfRzRH+H82XloK94tcs= |
| 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 | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1852.1369011907.3114.python-list@python.org> (permalink) |
| Lines | 61 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1369011907 news.xs4all.nl 15868 [2001:888:2000:d::a6]:56927 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:45577 |
Show key headers only | View raw
On 05/19/2013 05:46 PM, Dennis Lee Bieber wrote: > On Sun, 19 May 2013 10:38:14 +1000, Chris Angelico <rosuav@gmail.com> > declaimed the following in gmane.comp.python.general: > >> On Sun, May 19, 2013 at 10:02 AM, Carlos Nepomuceno >> <carlosnepomuceno@outlook.com> wrote: >>> I didn't know Python threads aren't preemptive. Seems to be something really old considering the state of the art on parallel execution on multi-cores. >>> >>> What's the catch on making Python threads preemptive? Are there any ongoing projects to make that? >> > <snip> > >> With interpreted code eg in CPython, it's easy to implement preemption >> in the interpreter. I don't know how it's actually done, but one easy >> implementation would be "every N bytecode instructions, context >> switch". It's still done at a lower level than user code (N bytecode > > Which IS how the common Python interpreter does it -- barring the > thread making some system call that triggers a preemption ahead of time > (even time.sleep(0.0) triggers scheduling). Forget if the default is 20 > or 100 byte-code instructions -- as I recall, it DID change a few > versions back. > > Part of the context switch is to transfer the GIL from the preempted > thread to the new thread. > > So, overall, on a SINGLE CORE processor running multiple CPU bound > threads takes a bit longer just due to the overhead of thread swapping. > > On a multi-core processor, the effect is the same, since -- even > though one may have a thread running on each core -- the GIL is only > assigned to one thread, and other threads get blocked when trying to > access runtime data structures. And you may have even more overhead from > processor cache misses if the a thread gets assigned to a different > core. > > (yes -- I'm restating the same thing as I had just trimmed below > this point... but the target is really the OP, where repetition may be > helpful in understanding) > So what's the mapping between real (OS) threads, and the fake ones Python uses? The OS keeps track of a separate stack and context for each thread it knows about; are they one-to-one with the ones you're describing here? If so, then any OS thread that gets scheduled will almost always find it can't get the GIL, and spend time thrashing. But the change that CPython does intentionally would be equivalent to a sleep(0). On the other hand, if these threads are distinct from the OS threads, is it done with some sort of thread pool, where CPython has its own stack, and doesn't really use the one managed by the OS? Understand the only OS threading I really understand is the one in Windows (which I no longer use). So assuming Linux has some form of lightweight threading, the distinction above may not map very well. -- DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Please help with Threading Jurgens de Bruin <debruinjj@gmail.com> - 2013-05-18 01:58 -0700
Re: Please help with Threading Peter Otten <__peter__@web.de> - 2013-05-18 11:09 +0200
Re: Please help with Threading Jurgens de Bruin <debruinjj@gmail.com> - 2013-05-18 04:23 -0700
Re: Please help with Threading Peter Otten <__peter__@web.de> - 2013-05-18 14:01 +0200
Re: Please help with Threading Dave Angel <davea@davea.name> - 2013-05-18 09:55 -0400
Re: Please help with Threading Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-05-18 15:28 -0400
RE: Please help with Threading Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-19 03:02 +0300
Re: Please help with Threading Chris Angelico <rosuav@gmail.com> - 2013-05-19 10:38 +1000
Re: Please help with Threading Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-05-19 17:46 -0400
Re: Please help with Threading Chris Angelico <rosuav@gmail.com> - 2013-05-20 07:52 +1000
Re: Please help with Threading Dave Angel <davea@davea.name> - 2013-05-19 21:04 -0400
Re: Please help with Threading Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-05-19 22:58 -0400
Re: Please help with Threading Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-05-19 23:25 -0400
Re: Please help with Threading Fábio Santos <fabiosantosart@gmail.com> - 2013-05-20 07:25 +0100
Re: Please help with Threading Jurgens de Bruin <debruinjj@gmail.com> - 2013-06-02 18:47 -0700
csiph-web