Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36767 > unrolled thread
| Started by | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| First post | 2013-01-14 04:16 +0000 |
| Last post | 2013-01-16 23:26 -0800 |
| Articles | 17 — 13 participants |
Back to article view | Back to comp.lang.python
Thought of the day Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-14 04:16 +0000
Re: Thought of the day Dave Angel <d@davea.name> - 2013-01-14 00:31 -0500
Re: Thought of the day Dan Sommers <dan@tombstonezero.net> - 2013-01-14 14:44 +0000
Re: Thought of the day Dave Angel <d@davea.name> - 2013-01-14 12:12 -0500
Re: Thought of the day alex23 <wuwei23@gmail.com> - 2013-01-14 04:09 -0800
Re: Thought of the day Tim Chase <python.list@tim.thechases.com> - 2013-01-14 08:15 -0600
Re: Thought of the day Chris Angelico <rosuav@gmail.com> - 2013-01-15 01:18 +1100
Re: Thought of the day Grant Edwards <invalid@invalid.invalid> - 2013-01-14 15:08 +0000
Re: Thought of the day Michael Torrie <torriem@gmail.com> - 2013-01-14 10:37 -0700
Re: Thought of the day John Gordon <gordon@panix.com> - 2013-01-14 18:09 +0000
Re: Thought of the day Michael Torrie <torriem@gmail.com> - 2013-01-14 11:25 -0700
Re: Thought of the day Dave Angel <d@davea.name> - 2013-01-14 09:31 -0500
Re: Thought of the day Antoine Pitrou <solipsis@pitrou.net> - 2013-01-15 16:48 +0000
Re: Thought of the day DJC <djc@news.invalid> - 2013-01-15 22:54 +0000
Re: Thought of the day Tim Golden <mail@timgolden.me.uk> - 2013-01-15 16:59 +0000
Re: Thought of the day Chris Angelico <rosuav@gmail.com> - 2013-01-16 07:27 +1100
Re: Thought of the day John Ladasky <john_ladasky@sbcglobal.net> - 2013-01-16 23:26 -0800
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-01-14 04:16 +0000 |
| Subject | Thought of the day |
| Message-ID | <50f3869d$0$29983$c3e8da3$5496439d@news.astraweb.com> |
A programmer had a problem, and thought Now he has "I know, I'll solve two it with threads!" problems. -- Steven
[toc] | [next] | [standalone]
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2013-01-14 00:31 -0500 |
| Message-ID | <mailman.492.1358155623.2939.python-list@python.org> |
| In reply to | #36767 |
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
[toc] | [prev] | [next] | [standalone]
| From | Dan Sommers <dan@tombstonezero.net> |
|---|---|
| Date | 2013-01-14 14:44 +0000 |
| Message-ID | <nRUIs.51167$On7.15414@newsfe16.iad> |
| In reply to | #36777 |
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, 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
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2013-01-14 12:12 -0500 |
| Message-ID | <mailman.505.1358183593.2939.python-list@python.org> |
| In reply to | #36788 |
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
[toc] | [prev] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2013-01-14 04:09 -0800 |
| Message-ID | <c5b02333-0309-4014-a474-92f9d66cdf6d@v9g2000pbi.googlegroups.com> |
| In reply to | #36767 |
On Jan 14, 2:16 pm, Steven D'Aprano <steve +comp.lang.pyt...@pearwood.info> 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 :)
[toc] | [prev] | [next] | [standalone]
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2013-01-14 08:15 -0600 |
| Message-ID | <mailman.495.1358172863.2939.python-list@python.org> |
| In reply to | #36767 |
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 python-list@python.org and on Google Groups". And now we have the problem of two threads... Intentionally-misinterpreting'ly yours, -tkc
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-01-15 01:18 +1100 |
| Message-ID | <mailman.496.1358173102.2939.python-list@python.org> |
| In reply to | #36767 |
On Tue, Jan 15, 2013 at 1:15 AM, Tim Chase <python.list@tim.thechases.com> wrote: > A newbie programmer had a problem and thought > > > > "I'll solve it by posting on > > > > python-list@python.org 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
[toc] | [prev] | [next] | [standalone]
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Date | 2013-01-14 15:08 +0000 |
| Message-ID | <kd170s$jo7$1@reader1.panix.com> |
| In reply to | #36767 |
On 2013-01-14, Steven D'Aprano <steve+comp.lang.python@pearwood.info> 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 ...
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2013-01-14 10:37 -0700 |
| Message-ID | <mailman.508.1358185089.2939.python-list@python.org> |
| In reply to | #36767 |
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.
[toc] | [prev] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2013-01-14 18:09 +0000 |
| Message-ID | <kd1hl0$679$1@reader1.panix.com> |
| In reply to | #36804 |
In <mailman.508.1358185089.2939.python-list@python.org> Michael Torrie <torriem@gmail.com> 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
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2013-01-14 11:25 -0700 |
| Message-ID | <mailman.511.1358187930.2939.python-list@python.org> |
| In reply to | #36807 |
On 01/14/2013 11:09 AM, John Gordon wrote: > In <mailman.508.1358185089.2939.python-list@python.org> Michael Torrie <torriem@gmail.com> 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.
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2013-01-14 09:31 -0500 |
| Message-ID | <mailman.535.1358257557.2939.python-list@python.org> |
| In reply to | #36767 |
On 01/14/2013 09:18 AM, Chris Angelico wrote: > On Tue, Jan 15, 2013 at 1:15 AM, Tim Chase > <python.list@tim.thechases.com> wrote: >> A newbie programmer had a problem and thought >> >> >> >> "I'll solve it by posting on >> >> >> >> python-list@python.org 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
[toc] | [prev] | [next] | [standalone]
| From | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| Date | 2013-01-15 16:48 +0000 |
| Message-ID | <mailman.542.1358268513.2939.python-list@python.org> |
| In reply to | #36767 |
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?
[toc] | [prev] | [next] | [standalone]
| From | DJC <djc@news.invalid> |
|---|---|
| Date | 2013-01-15 22:54 +0000 |
| Message-ID | <kd4mo2$2ec$1@dont-email.me> |
| In reply to | #36859 |
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
[toc] | [prev] | [next] | [standalone]
| From | Tim Golden <mail@timgolden.me.uk> |
|---|---|
| Date | 2013-01-15 16:59 +0000 |
| Message-ID | <mailman.543.1358269202.2939.python-list@python.org> |
| In reply to | #36767 |
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
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-01-16 07:27 +1100 |
| Message-ID | <mailman.550.1358281634.2939.python-list@python.org> |
| In reply to | #36767 |
On Wed, Jan 16, 2013 at 3:48 AM, Antoine Pitrou <solipsis@pitrou.net> 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
[toc] | [prev] | [next] | [standalone]
| From | John Ladasky <john_ladasky@sbcglobal.net> |
|---|---|
| Date | 2013-01-16 23:26 -0800 |
| Message-ID | <8c6a2f88-08ba-48f2-aca8-daa3c8400593@googlegroups.com> |
| In reply to | #36767 |
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web