Re: basic thread question

Discussion in 'Python' started by Derek Martin, Aug 18, 2009.

  1. Derek Martin

    Derek Martin Guest

    On Tue, Aug 18, 2009 at 03:10:15PM -0500, Derek Martin wrote:
    > I have some simple threaded code... If I run this
    > with an arg of 1 (start one thread), it pegs one cpu, as I would
    > expect. If I run it with an arg of 2 (start 2 threads), it uses both
    > CPUs, but utilization of both is less than 50%. Can anyone explain
    > why?


    Ah, searching while waiting for an answer (the e-mail gateway is a bit
    slow, it seems...) I discovered that the GIL is the culprate.
    Evidently this question comes up a lot. It would probably save a lot
    of time on the part of those who answer questions here, as well as
    those implementing solutions in Python, if whoever is maintaining the
    docs these days would put a blurb about this in the docs in big bold
    letters... Concurrency being perhaps the primary reason to use
    threading, essentially it means that Python is not useful for the
    sorts of problems that one would be inclined to solve they way my code
    works (or rather, was meant to). It would be very helpful to know
    that *before* one tried to implement a solution that way... especially
    for solutions significantly less trivial than mine. ;-)

    Thanks

    --
    Derek D. Martin
    http://www.pizzashack.org/
    GPG Key ID: 0x81CFE75D


    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.5 (GNU/Linux)

    iD8DBQFKiyjOdjdlQoHP510RAs15AJ0ckKZ5NL7l0aGk9xNVcmN+DVGCQQCff9+l
    OK0dtK6mImXRf6TQ9dLb1as=
    =KuKR
    -----END PGP SIGNATURE-----
    Derek Martin, Aug 18, 2009
    #1
    1. Advertising

  2. Derek Martin

    birdsong Guest

    On Aug 18, 3:18 pm, Derek Martin <> wrote:
    > On Tue, Aug 18, 2009 at 03:10:15PM -0500, Derek Martin wrote:
    > > I have some simple threaded code...  If I run this
    > > with an arg of 1 (start one thread), it pegs one cpu, as I would
    > > expect.  If I run it with an arg of 2 (start 2 threads), it uses both
    > > CPUs, but utilization of both is less than 50%.  Can anyone explain
    > > why?  

    >
    > Ah, searching while waiting for an answer (the e-mail gateway is a bit
    > slow, it seems...) I discovered that the GIL is the culprate.
    > Evidently this question comes up a lot.  It would probably save a lot
    > of time on the part of those who answer questions here, as well as
    > those implementing solutions in Python, if whoever is maintaining the
    > docs these days would put a blurb about this in the docs in big bold
    > letters...  Concurrency being perhaps the primary reason to use
    > threading, essentially it means that Python is not useful for the
    > sorts of problems that one would be inclined to solve they way my code
    > works (or rather, was meant to).  It would be very helpful to know
    > that *before* one tried to implement a solution that way... especially
    > for solutions significantly less trivial than mine. ;-)
    >
    > Thanks
    >
    > --
    > Derek D. Martinhttp://www.pizzashack.org/
    > GPG Key ID: 0x81CFE75D
    >
    >  application_pgp-signature_part
    > < 1KViewDownload


    I would still watch that video which will explain a bit more about the
    GIL.
    birdsong, Aug 19, 2009
    #2
    1. Advertising

  3. Derek Martin

    Sean DiZazzo Guest

    On Aug 18, 4:58 pm, birdsong <> wrote:
    > On Aug 18, 3:18 pm, Derek Martin <> wrote:
    >
    >
    >
    > > On Tue, Aug 18, 2009 at 03:10:15PM -0500, Derek Martin wrote:
    > > > I have some simple threaded code...  If I run this
    > > > with an arg of 1 (start one thread), it pegs one cpu, as I would
    > > > expect.  If I run it with an arg of 2 (start 2 threads), it uses both
    > > > CPUs, but utilization of both is less than 50%.  Can anyone explain
    > > > why?  

    >
    > > Ah, searching while waiting for an answer (the e-mail gateway is a bit
    > > slow, it seems...) I discovered that the GIL is the culprate.
    > > Evidently this question comes up a lot.  It would probably save a lot
    > > of time on the part of those who answer questions here, as well as
    > > those implementing solutions in Python, if whoever is maintaining the
    > > docs these days would put a blurb about this in the docs in big bold
    > > letters...  Concurrency being perhaps the primary reason to use
    > > threading, essentially it means that Python is not useful for the
    > > sorts of problems that one would be inclined to solve they way my code
    > > works (or rather, was meant to).  It would be very helpful to know
    > > that *before* one tried to implement a solution that way... especially
    > > for solutions significantly less trivial than mine. ;-)

    >
    > > Thanks

    >
    > > --
    > > Derek D. Martinhttp://www.pizzashack.org/
    > > GPG Key ID: 0x81CFE75D

    >
    > >  application_pgp-signature_part
    > > < 1KViewDownload

    >
    > I would still watch that video which will explain a bit more about the
    > GIL.


    Thank you for the video! It's good to know, but it raises lots of
    other questions in my mind. Lots of examples would have helped.

    ~Sean
    Sean DiZazzo, Aug 20, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. john
    Replies:
    4
    Views:
    563
    Lee Fesperman
    Jun 3, 2005
  2. Engineer
    Replies:
    6
    Views:
    603
    Jeremy Bowers
    May 1, 2005
  3. Replies:
    0
    Views:
    417
  4. Derek Martin

    basic thread question

    Derek Martin, Aug 18, 2009, in forum: Python
    Replies:
    2
    Views:
    260
    sturlamolden
    Aug 24, 2009
  5. Jan Kaliszewski

    Re: basic thread question

    Jan Kaliszewski, Aug 18, 2009, in forum: Python
    Replies:
    10
    Views:
    499
    sturlamolden
    Aug 25, 2009
Loading...

Share This Page