RE: Please help with Threading

Discussion in 'Python' started by Carlos Nepomuceno, May 20, 2013.

  1. ----------------------------------------
    > Date: Mon, 20 May 2013 17:45:14 +1000
    > From:
    > To:
    > Subject: Re: Please help with Threading
    > CC: ;
    >
    > On 20May2013 07:25, Fábio Santos <> wrote:
    > | On 18 May 2013 20:33, "Dennis Lee Bieber" <> wrote:
    > |> Python threads work fine if the threads either rely on intelligent
    > |> DLLs for number crunching (instead of doing nested Python loops to
    > |> process a numeric array you pass it to something like NumPy which
    > |> releases the GIL while crunching a copy of the array) or they do lots of
    > |> I/O and have to wait for I/O devices (while one thread is waiting for
    > |> the write/read operation to complete, another thread can do some number
    > |> crunching).
    > |
    > | Has nobody thought of a context manager to allow a part of your code to
    > | free up the GIL? I think the GIL is not inherently bad, but if it poses a
    > | problem at times, there should be a way to get it out of your... Way.
    >
    > The GIL makes individual python operations thread safe by never
    > running two at once. This makes the implementation of the operations
    > simpler, faster and safer. It is probably totally infeasible to
    > write meaningful python code inside your suggested context
    > manager that didn't rely on the GIL; if the GIL were not held the
    > code would be unsafe.


    I just got my hands dirty trying to synchronize Python prints from many threads.
    Sometimes they mess up when printing the newlines.

    I tried several approaches using threading.Lock and Condition. None of themworked perfectly and all of them made the code sluggish.

    Is there a 100% sure method to make print thread safe? Can it be fast???


    > It is easy for a C extension to release the GIL, and then to do
    > meaningful work until it needs to return to python land. Most C
    > extensions will do that around non-trivial sections, and anything
    > that may stall in the OS.
    >
    > So your use case for the context manager doesn't fit well.
    > --
    > Cameron Simpson <>
    >
    > Gentle suggestions being those which are written on rocks of less than 5lbs.
    > - Tracy Nelson in comp.lang.c
    > --
    > http://mail.python.org/mailman/listinfo/python-list
     
    Carlos Nepomuceno, May 20, 2013
    #1
    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. KK
    Replies:
    2
    Views:
    651
    Big Brian
    Oct 14, 2003
  2. Replies:
    9
    Views:
    1,081
    Mark Space
    Dec 29, 2007
  3. silkenpy
    Replies:
    1
    Views:
    356
    Dennis Lee Bieber
    Feb 15, 2008
  4. Steven Woody
    Replies:
    0
    Views:
    444
    Steven Woody
    Jan 9, 2009
  5. Steven Woody
    Replies:
    0
    Views:
    464
    Steven Woody
    Jan 9, 2009
Loading...

Share This Page