Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69714

Re: About threading.Thread

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'argument': 0.05; 'arguments': 0.09; 'function,': 0.09; 'happen.': 0.09; 'subject:skip:t 10': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'thread': 0.14; 'called,': 0.16; 'file1': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'infinitely': 0.16; 'parentheses': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'advance.': 0.19; 'seems': 0.21; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'pass': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'getting': 0.31; 'that.': 0.31; 'subject:About': 0.31; 'anyone': 0.31; 'problem': 0.35; 'problem.': 0.35; 'definition': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'two': 0.37; 'list.': 0.37; 'thank': 0.38; 'files': 0.38; 'pm,': 0.38; 'rather': 0.38; 'explain': 0.39; 'called': 0.40; 'skip:t 30': 0.61; 'new': 0.61; "you're": 0.61; "you'll": 0.62; 'skip:n 10': 0.64; 'here': 0.66; 'fact,': 0.69; 'cut': 0.74; 'this;': 0.91; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=ZTr2pe02XFSfTKIZhXFb7I3PBSsq/73VoH52LY+Ofcc=; b=jpsN7o4g8jawSNj70uvpB5/o9yOh6fC0/3QavMSjEW827eZtkWwce/j5Fzf17qo0Bl cMogHTFM6hgVer7gT+RU0adeGIOTq7wOMk0lN/XPGbcdEC0aQv9IMgX1NAZm4JR84PSF wpOBgYeSoYzwkE6xg6pOHm/tVUwWXdiycVigwHY/MjgPZmtmXghLMz1jfcomXvDnAVjz aHo/K0MbX0gTbzx7+95EZdwZnRsLwtJxl31jW9Kb1bMrcViVHMjwEf8q6dqIx3SMpOhl 0VNrvoyb/4rVqm6YghOhcafIAKRzJhcUb1Nzzgaa1w/S2vvk9+IoVNLzsstk+L7/mWe8 fMTA==
MIME-Version 1.0
X-Received by 10.66.233.72 with SMTP id tu8mr12617632pac.112.1396675346608; Fri, 04 Apr 2014 22:22:26 -0700 (PDT)
In-Reply-To <BLU402-EAS3761BB1DD75580AE06D38FA9D6E0@phx.gbl>
References <BLU402-EAS3761BB1DD75580AE06D38FA9D6E0@phx.gbl>
Date Sat, 5 Apr 2014 16:22:26 +1100
Subject Re: About threading.Thread
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.8919.1396675349.18130.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1396675349 news.xs4all.nl 2901 [2001:888:2000:d::a6]:57177
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:69714

Show key headers only | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: About threading.Thread Chris Angelico <rosuav@gmail.com> - 2014-04-05 16:22 +1100

csiph-web