Thought of the day

Discussion in 'Python' started by Steven D'Aprano, Jan 14, 2013.

  1. A programmer had a problem, and thought Now he has "I know, I'll solve
    two it with threads!" problems.



    --
    Steven
    Steven D'Aprano, Jan 14, 2013
    #1
    1. Advertising

  2. Steven D'Aprano

    Dave Angel Guest

    On 01/13/2013 11:16 PM, Steven D'Aprano wrote:
    > A programmer had a problem, and thought Now he has "I know, I'll solve
    > two it with threads!" problems.
    >
    >


    ++10

    I've been thinking about threads lately, and have come to the tentative
    conclusion that they're a solution which has outlived its usefulness for
    99% of the use cases. Much like the Windows 3.1 model of memory usage,
    where all memory was shared, and apps promised not to step too hard on
    each other. Or the "640k is more memory than any application will ever
    need" notion.

    When you multiprocess, everything is private except those things you
    work at sharing. When you multithread, everything is shared, and you
    promise not to intentionally do anything too nasty with the ability.

    --

    DaveA
    Dave Angel, Jan 14, 2013
    #2
    1. Advertising

  3. Steven D'Aprano

    alex23 Guest

    On Jan 14, 2:16 pm, Steven D'Aprano <steve
    > wrote:
    > A programmer had a problem, and thought Now he has "I know, I'll solve
    > two it with threads!" problems.


    I laughed far far longer than I should have, cheers :)
    alex23, Jan 14, 2013
    #3
  4. Steven D'Aprano

    Tim Chase Guest

    On 01/13/13 22:16, Steven D'Aprano wrote:
    > A programmer had a problem, and thought Now he has "I know, I'll
    > solve two it with threads!" problems.


    A newbie programmer had a problem and thought "I'll solve it by
    posting on and on Google Groups". And now we
    have the problem of two threads...

    Intentionally-misinterpreting'ly yours,

    -tkc
    Tim Chase, Jan 14, 2013
    #4
  5. On Tue, Jan 15, 2013 at 1:15 AM, Tim Chase
    <> wrote:
    > A newbie programmer had a problem and thought
    >
    >
    >
    > "I'll solve it by posting on
    >
    >
    >
    > and on Google Groups".
    >
    >
    >
    > And now we have the problem of two threads...


    And, when faced with problems of having two threads, the most obvious
    solution is to add sleep() calls, so it looks like the above... Am I
    dragging the analogy out too far?

    ChrisA
    Chris Angelico, Jan 14, 2013
    #5
  6. Steven D'Aprano

    Dave Angel Guest

    On 01/14/2013 09:18 AM, Chris Angelico wrote:
    > On Tue, Jan 15, 2013 at 1:15 AM, Tim Chase
    > <> wrote:
    >> A newbie programmer had a problem and thought
    >>
    >>
    >>
    >> "I'll solve it by posting on
    >>
    >>
    >>
    >> and on Google Groups".
    >>
    >>
    >>
    >> And now we have the problem of two threads...

    > And, when faced with problems of having two threads, the most obvious
    > solution is to add sleep() calls, so it looks like the above... Am I
    > dragging the analogy out too far?
    >
    > ChrisA


    Naaah, too far would be trying to relate the GIL to KILL files. For
    example, I avoid the google groups double-post syndrome by killfiling
    any message with google-groups in the To: or CC: fields. 596 messages
    in six months. I still get the second copy.




    --

    DaveA
    Dave Angel, Jan 14, 2013
    #6
  7. On 2013-01-14, Steven D'Aprano <> wrote:

    > A programmer had a problem, and thought Now he has "I know, I'll solve
    > two it with threads!" problems.


    :)

    That took a few seconds -- must be the cold.

    --
    Grant Edwards grant.b.edwards Yow! I hope I bought the
    at right relish ... zzzzzzzzz
    gmail.com ...
    Grant Edwards, Jan 14, 2013
    #7
  8. Steven D'Aprano

    Dave Angel Guest

    On 01/14/2013 09:44 AM, Dan Sommers wrote:
    > On Mon, 14 Jan 2013 00:31:59 -0500, Dave Angel wrote:
    >
    >> On 01/13/2013 11:16 PM, Steven D'Aprano wrote:
    >>> A programmer had a problem, and thought Now he has "I know, I'll solve
    >>> two it with threads!" problems.

    >> ++10

    > It took me a moment to figure it out, but in the end I smiled and I
    > agree: +1.
    >
    >> I've been thinking about threads lately, and have come to the tentative
    >> conclusion that they're a solution which has outlived its usefulness for
    >> 99% of the use cases. Much like the Windows 3.1 model of memory usage,
    >> where all memory was shared, and apps promised not to step too hard on
    >> each other. Or the "640k is more memory than any application will ever
    >> need" notion.

    > With this, however, I don't agree. If Python's GIL didn't interfere with
    > the concurrency of threads,


    Better minds than mine have tried very hard to eliminate the GIL, so for
    now I consider that a feature of Python. If the GIL weren't needed for
    the lowest levels of the interpreter, something else would be needed for
    all the possible data structures that need atomic updates. Hello
    semaphores, mutexes, etc. If threading were considered important in a
    language, it'd have a way to declare an object sharable (default off),
    and the low level code would go at full speed for any object not so
    declared. But the language would then provide guarantees for the
    standard objects that are marked as sharable. That's not current Python.

    > I can't think of a good reason to use
    > multiple processes instead, except to use a tool that runs outside the
    > Python virtual machine, or to provide more fault tolerance for long-
    > running server-like applications. We're all adults here, and if the
    > policy is to invoke the methods of objects as documented, then that
    > policy extends to stepping on (or not stepping on) the memory of other
    > threads, too.
    >
    > The APIs for threads and processes is pretty much the same, so I suppose
    > it doesn't matter much, either. Use the right tool for the job.
    >
    > Dan


    For other languages, I've done extensive work on projects with heavy
    multithreading, and getting it right is extremely difficult. Another
    way of putting it is that any non-trivial project with multithreading is
    probably buggy.



    --

    DaveA
    Dave Angel, Jan 14, 2013
    #8
  9. On 01/13/2013 09:16 PM, Steven D'Aprano wrote:
    > A programmer had a problem, and thought Now he has "I know, I'll solve
    > two it with threads!" problems.


    The same applies to regular expressions, which is actually what the
    expression was first used with years ago. Probably applies to just
    about any technology. Including Java.
    Michael Torrie, Jan 14, 2013
    #9
  10. Steven D'Aprano

    John Gordon Guest

    In <> Michael Torrie <> writes:

    > On 01/13/2013 09:16 PM, Steven D'Aprano wrote:
    > > A programmer had a problem, and thought Now he has "I know, I'll solve
    > > two it with threads!" problems.


    > The same applies to regular expressions, which is actually what the
    > expression was first used with years ago. Probably applies to just
    > about any technology. Including Java.


    Steven cleverly worded it in such a way as to apply directly to threads.
    The sentences are jumbled and interleaved, as if they were the output of
    two threads that are not synchronized.

    --
    John Gordon A is for Amy, who fell down the stairs
    B is for Basil, assaulted by bears
    -- Edward Gorey, "The Gashlycrumb Tinies"
    John Gordon, Jan 14, 2013
    #10
  11. On 01/14/2013 11:09 AM, John Gordon wrote:
    > In <> Michael Torrie <> writes:
    >
    >> On 01/13/2013 09:16 PM, Steven D'Aprano wrote:
    >>> A programmer had a problem, and thought Now he has "I know, I'll solve
    >>> two it with threads!" problems.

    >
    >> The same applies to regular expressions, which is actually what the
    >> expression was first used with years ago. Probably applies to just
    >> about any technology. Including Java.

    >
    > Steven cleverly worded it in such a way as to apply directly to threads.
    > The sentences are jumbled and interleaved, as if they were the output of
    > two threads that are not synchronized.


    Very true! Guess I was too distracted by Python's warts to notice. Haha.
    Michael Torrie, Jan 14, 2013
    #11
  12. Steven D'Aprano <steve+comp.lang.python <at> pearwood.info> writes:
    >
    > A programmer had a problem, and thought Now he has "I know, I'll solve
    > two it with threads!" problems.



    Host: Last week the Royal Festival Hall saw the first performance of a new
    logfile by one of the world's leading modern programmers, Steven
    "Two threads" D'Aprano. Mr D'Aprano.

    D'Aprano: Hello.

    Host: May I just sidetrack for one moment. This -- what shall I call it --
    nickname of yours...

    D'Aprano: Ah yes.

    Host: "Two threads". How did you come by it?

    D'Aprano: Well, I don't use it myself, but some of my friends call me "Two
    Threads".

    Host: And do you in fact have two threads?

    D'Aprano: No, I've only got one. I've had one for some time, but a few
    years ago I said I was thinking of spawning another, and since then some
    people have called me "Two Threads".

    Host: In spite of the fact that you only have one.

    D'Aprano: Yes.

    Host: And are you still intending to spawn this second thread?

    D'Aprano: (impatient) No!

    Host: ...To bring you in line with your epithet?

    D'Aprano: No.

    Host: I see, I see. Well to return to your program.

    D'Aprano: Ah yes.

    Host: Did you write this logfile in the thread?

    D'Aprano: (surprised) No!

    Host: Have you written any of your recent files in this thread of yours?

    D'Aprano: No, no, not at all. It's just an ordinary daemon thread.

    Host: I see, I see. And you're thinking of spawning this second thread to
    write in!

    D'Aprano: No, no. Look. This thread business -- it doesn't really matter.
    The threads aren't important. A few friends call me Two Threads and that's
    all there is to it. I wish you'd ask me about the logfile. Everybody talks
    about the threads. They've got it out of proportion -- I'm a programmer.
    I'm going to get rid of the thread. I'm fed up with it!

    Host: Then you'll be Steven "No Threads" D'Aprano, eh?
    Antoine Pitrou, Jan 15, 2013
    #12
  13. Steven D'Aprano

    Tim Golden Guest

    On 15/01/2013 16:48, Antoine Pitrou wrote:
    > Steven D'Aprano <steve+comp.lang.python <at> pearwood.info> writes:
    >>
    >> A programmer had a problem, and thought Now he has "I know, I'll solve
    >> two it with threads!" problems.

    >
    >
    > Host: Last week the Royal Festival Hall saw the first performance of a new
    > logfile by one of the world's leading modern programmers, Steven
    > "Two threads" D'Aprano. Mr D'Aprano.


    [... snip ...]

    Brilliant, just brilliant.

    TJG
    Tim Golden, Jan 15, 2013
    #13
  14. On Wed, Jan 16, 2013 at 3:48 AM, Antoine Pitrou <> wrote:
    > D'Aprano: No, no. Look. This thread business -- it doesn't really matter.
    > The threads aren't important. A few friends call me Two Threads and that's
    > all there is to it. I wish you'd ask me about the logfile. Everybody talks
    > about the threads. They've got it out of proportion -- I'm a programmer.
    > I'm going to get rid of the thread. I'm fed up with it!
    >
    > Host: Then you'll be Steven "No Threads" D'Aprano, eh?


    Close, Host. He'd be Steven "No Marbles" D'Aprano.

    *whistles innocently*

    ChrisA
    Chris Angelico, Jan 15, 2013
    #14
  15. Steven D'Aprano

    DJC Guest

    On 15/01/13 16:48, Antoine Pitrou wrote:
    > Steven D'Aprano <steve+comp.lang.python <at> pearwood.info> writes:
    >>
    >> A programmer had a problem, and thought Now he has "I know, I'll solve
    >> two it with threads!" problems.

    >
    >
    > Host: Last week the Royal Festival Hall saw the first performance of a new
    > logfile by one of the world's leading modern programmers, Steven
    > "Two threads" D'Aprano. Mr D'Aprano.
    >
    > D'Aprano: Hello.
    >
    > Host: May I just sidetrack for one moment. This -- what shall I call it --
    > nickname of yours...
    >
    > D'Aprano: Ah yes.
    >
    > Host: "Two threads". How did you come by it?

    [...]
    > Host: I see, I see. And you're thinking of spawning this second thread to
    > write in!
    >
    > D'Aprano: No, no. Look. This thread business -- it doesn't really matter.
    > The threads aren't important. A few friends call me Two Threads and that's
    > all there is to it. I wish you'd ask me about the logfile. Everybody talks
    > about the threads. They've got it out of proportion -- I'm a programmer.
    > I'm going to get rid of the thread. I'm fed up with it!
    >
    > Host: Then you'll be Steven "No Threads" D'Aprano, eh?



    + Applause
    DJC, Jan 15, 2013
    #15
  16. Steven D'Aprano

    John Ladasky Guest

    On Sunday, January 13, 2013 8:16:29 PM UTC-8, Steven D'Aprano wrote:
    > A programmer had a problem, and thought Now he has "I know, I'll solve
    > two it with threads!" problems.


    Very nice! :^)

    This problem isn't exclusive to Python, however. Other multi-threaded applications can produce jumbled output like this, even when the threads (processes?) are running on independent CPU's.

    I use a very well-regarded application for molecular dynamics simulation: GROMACS, which I believe is written mostly in C (but there's even a little Fortran in it? And supposedly, this is critical to performance?). The GROMACS core program, mdrun, will grab as many CPUs as you allow it to use. The output of mdrun looks exactly like your little quip as each CPU reports back that it has started its piece of mdrun.
    John Ladasky, Jan 17, 2013
    #16
    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. Andy
    Replies:
    1
    Views:
    702
  2. Replies:
    2
    Views:
    274
  3. Rob Redmon

    Convert day of year to month, day

    Rob Redmon, Apr 4, 2008, in forum: Ruby
    Replies:
    7
    Views:
    297
    Alex Wayne
    Apr 4, 2008
  4. Demian Brecht

    Re: Thought of the day

    Demian Brecht, Jan 14, 2013, in forum: Python
    Replies:
    0
    Views:
    144
    Demian Brecht
    Jan 14, 2013
  5. Demian Brecht

    Re: Thought of the day

    Demian Brecht, Jan 14, 2013, in forum: Python
    Replies:
    0
    Views:
    126
    Demian Brecht
    Jan 14, 2013
Loading...

Share This Page