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: 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: References: Date: Sat, 5 Apr 2014 16:22:26 +1100 Subject: Re: About threading.Thread From: Chris Angelico Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Sat, Apr 5, 2014 at 4:02 PM, =E5=BC=A0=E4=BD=A9=E4=BD=A9 wrote: > def fun(): > a =3D threading.Thread(target=3Dhello(), name=3D'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 =3D threading.Thread(target=3Dhello, name=3D'hello') That'll pass a function, rather than the return value of that function, and then Thread can call that. ChrisA