a very newbie question about threading

Discussion in 'Python' started by Chris Patton, Nov 13, 2004.

  1. Chris Patton

    Chris Patton Guest

    Hey Everyone.

    I've recenently stumbled upon a concept known as "threading". Can
    anyone tell me what this IS and how it is used, or show me where I can
    get information about this?

    Thanks!
     
    Chris Patton, Nov 13, 2004
    #1
    1. Advertising

  2. Chris Patton

    Chris S. Guest

    Chris Patton wrote:

    > Hey Everyone.
    >
    > I've recenently stumbled upon a concept known as "threading". Can
    > anyone tell me what this IS and how it is used, or show me where I can
    > get information about this?
    >
    > Thanks!


    Threading, or multi-threading, involves the simultaneous execution of
    multiple sequences (e.g. "threads") of instructions. This is similar to
    how your computer runs several programs at the same time, except threads
    usually share the same space in memory, so they can easily operate on
    shared data. As always, Google and Python's docs are your friends:

    http://www.google.com/search?hl=en&lr=&q=what is multi-threading&btnG=Search
    http://docs.python.org/lib/module-threading.html
     
    Chris S., Nov 13, 2004
    #2
    1. Advertising

  3. Chris Patton

    Mike Meyer Guest

    (Chris Patton) writes:

    > I've recenently stumbled upon a concept known as "threading". Can
    > anyone tell me what this IS and how it is used, or show me where I can
    > get information about this?


    Now that you know what they are - be warned that they tend to be a
    source of very hard to track down bugs. If you can avoid writing
    threaded code, do so. One common use of threads is to handle multiple
    IO streams at one time. Asyncore is a much saner solution to that
    problem.

    <mike
    --
    Mike Meyer <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
     
    Mike Meyer, Nov 13, 2004
    #3
  4. Chris Patton

    Peter Hansen Guest

    Jeremy Bowers wrote:
    > On Fri, 12 Nov 2004 16:29:53 -0800, Chris Patton wrote:
    >>I've recenently stumbled upon a concept known as "threading".

    >
    > I'd add that with no insult intended, "threading" and "very newbie" do not
    > go together well. Threading is the most common source of the notorious
    > "heisenbug", ...
    > Generally, unless you *know* you need them, you don't, ...


    Excellent post, Jeremy, though I think it's worth adding something
    like this:

    Python makes writing threaded code much more straightforward than
    many languages, and also provides some protection from some types
    of bugs which are almost ubiquitous in threaded applications in
    some other languages. By sticking with the Queue object (see the
    module by that name) as the sole means of communication between
    threads, the vast majority of other thread-related problems
    simply disappears. Not all of them -- and Jeremy's caution about
    threads giving even expert programmers pause applies -- but in
    general Python's not a bad place to learn and use threads...

    -Peter
     
    Peter Hansen, Nov 13, 2004
    #4
  5. On Fri, 12 Nov 2004 16:29:53 -0800, Chris Patton wrote:

    > Hey Everyone.
    >
    > I've recenently stumbled upon a concept known as "threading". Can
    > anyone tell me what this IS and how it is used, or show me where I can
    > get information about this?


    Chris S. gave you the bare-bones basic.

    I'd add that with no insult intended, "threading" and "very newbie" do not
    go together well. Threading is the most common source of the notorious
    "heisenbug", that randomly appears and disappears, resisting capture and
    elimination by even the best of 'em. It's a complicated topic that gives
    even the most expert programmers pause. I'm not exaggerating in the
    slightest.

    Generally, unless you *know* you need them, you don't, and there are ways
    around using threads. Threads are kind of like the old "goto" statements;
    it isn't that the idea of "goto" is intrinsically bad, it is just that
    without discipline they rapidly become more problem than solution. So
    instead of "goto", we use certain special cases of them, like function
    calls and loops, that behave much more nicely. Most thread uses can
    equally well be satisfied with certain other "special cases" that are much
    less dangerous, like the "async" module for processing multiple incoming
    files(/sockets/pipes whatever), or firing off seperate processes for long
    running computations.

    That said, I have used them when they were the best tool for the job. But
    raw threads scare me every time.
     
    Jeremy Bowers, Nov 13, 2004
    #5
  6. On Fri, 12 Nov 2004 23:01:37 -0500, Peter Hansen wrote:
    > Python makes writing threaded code much more straightforward than many
    > languages, and also provides some protection from some types of bugs which
    > are almost ubiquitous in threaded applications in some other languages.
    > By sticking with the Queue object (see the module by that name) as the
    > sole means of communication between threads, the vast majority of other
    > thread-related problems simply disappears. Not all of them -- and
    > Jeremy's caution about threads giving even expert programmers pause
    > applies -- but in general Python's not a bad place to learn and use
    > threads...


    I've been looking over the recently announced "Candygram" module, too, and
    while I must admit I haven't used it it does look **very** nice and I
    think I will next time it makes sense.

    http://candygram.sourceforge.net/

    Took me a little bit to figure out exactly how to ask a foreign thread for
    a value synchronously but the sample program "program_5.2.py" shows how
    (and the _alt program does it in Python better). This makes more sense if
    you read along in the Erlang book as suggested.
     
    Jeremy Bowers, Nov 14, 2004
    #6
  7. Chris Patton

    Jorgen Grahn Guest

    On Fri, 12 Nov 2004 21:59:04 -0600, Mike Meyer <> wrote:
    > (Chris Patton) writes:
    >
    >> I've recenently stumbled upon a concept known as "threading". Can
    >> anyone tell me what this IS and how it is used, or show me where I can
    >> get information about this?

    >
    > Now that you know what they are - be warned that they tend to be a
    > source of very hard to track down bugs. If you can avoid writing
    > threaded code, do so. One common use of threads is to handle multiple
    > IO streams at one time. Asyncore is a much saner solution to that
    > problem.


    For more threading criticism along those lines, see Eric Raymond's TAOUP:

    http://www.catb.org/~esr/writings/taoup/html/ch07s03.html#id2923889

    /Jorgen

    --
    // Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
    \X/ algonet.se> R'lyeh wgah'nagl fhtagn!
     
    Jorgen Grahn, Nov 16, 2004
    #7
    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. Raymond Arthur St. Marie II of III

    very Very VERY dumb Question About The new Set( ) 's

    Raymond Arthur St. Marie II of III, Jul 23, 2003, in forum: Python
    Replies:
    4
    Views:
    499
    Raymond Hettinger
    Jul 27, 2003
  2. shanx__=|;-

    very very very long integer

    shanx__=|;-, Oct 16, 2004, in forum: C Programming
    Replies:
    19
    Views:
    1,678
    Merrill & Michele
    Oct 19, 2004
  3. Abhishek Jha

    very very very long integer

    Abhishek Jha, Oct 16, 2004, in forum: C Programming
    Replies:
    4
    Views:
    445
    jacob navia
    Oct 17, 2004
  4. Peter

    Very very very basic question

    Peter, Feb 8, 2005, in forum: C Programming
    Replies:
    14
    Views:
    526
    Dave Thompson
    Feb 14, 2005
  5. olivier.melcher

    Help running a very very very simple code

    olivier.melcher, May 12, 2008, in forum: Java
    Replies:
    8
    Views:
    2,328
Loading...

Share This Page