Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69714 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2014-04-05 16:22 +1100 |
| Last post | 2014-04-05 16:22 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: About threading.Thread Chris Angelico <rosuav@gmail.com> - 2014-04-05 16:22 +1100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-04-05 16:22 +1100 |
| Subject | Re: About threading.Thread |
| Message-ID | <mailman.8919.1396675349.18130.python-list@python.org> |
On Sat, Apr 5, 2014 at 4:02 PM, 张佩佩 <zhangpeipei812@outlook.com> wrote: > def fun(): > a = threading.Thread(target=hello(), name='hello') > It seems that threading.Thread() in file1 not create a new thread but use MainThread. > Anyone can explain this ? > Thank you in advance. Suggestion: Cut the code down until you find the exact bit that's showing a problem. You don't need two files for this; in fact, all you need is your definition of hello, the call to threading.Thread(), and a print statement after it, which you'll see doesn't happen. The problem here is that you're already *calling* hello() in the argument list. Before threading.Thread() gets called, its arguments get fully evaluated... which calls hello(), which infinitely loops. That's why it's getting called on the main thread. To spin off a thread that will call hello(), take the parentheses off: a = threading.Thread(target=hello, name='hello') That'll pass a function, rather than the return value of that function, and then Thread can call that. ChrisA
Back to top | Article view | comp.lang.python
csiph-web