Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45566
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: Please help with Threading |
| Date | 2013-05-19 17:46 -0400 |
| Organization | > Bestiaria Support Staff < |
| References | <7baacf5a-0c50-4935-ad5b-148c208d759b@googlegroups.com> <13lfp8lds6e2e41rtsnvqimcb6inu7p28o@invalid.netcom.com> <BLU176-W444B989132C26C3A305CB7D7AE0@phx.gbl> <CAPTjJmoJExzBAg7LXodAJVLCe=dpUqOqeUjzXLCWWzxbqz=vEQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1848.1368999978.3114.python-list@python.org> (permalink) |
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)
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
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