Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '21,': 0.07; 'see:': 0.07; 'clean.': 0.09; 'imported': 0.09; 'imports': 0.09; 'indirectly': 0.09; 'restriction': 0.09; 'sentence': 0.09; 'subtle': 0.09; 'cc:addr:python-list': 0.10; 'thread': 0.11; 'sat,': 0.15; 'crop': 0.16; 'deadlock': 0.16; 'not;': 0.16; 'preexisting': 0.16; 'strange,': 0.16; 'subject:import': 0.16; 'thread.': 0.16; 'threading': 0.16; 'wrote:': 0.17; 'module,': 0.17; 'why.': 0.17; 'import': 0.21; 'thanks.': 0.21; 'subject:problem': 0.22; 'cc:2**0': 0.23; 'bruce': 0.23; 'statement': 0.23; "haven't": 0.23; "i've": 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'script': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'module.': 0.27; "doesn't": 0.28; 'gather': 0.29; 'implies': 0.29; 'url:python': 0.32; 'could': 0.32; 'cases,': 0.33; 'docs': 0.33; 'list': 0.35; 'pm,': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'test': 0.36; 'should': 0.36; 'problems': 0.36; 'enough': 0.36; 'does': 0.37; 'two': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'some': 0.38; 'url:docs': 0.38; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'end': 0.40; 'your': 0.60; 'easy': 0.60; 'side': 0.61; '(that': 0.62; 'strange': 0.62; 'more': 0.63; 'behavior': 0.64; 'jul': 0.65; 'header:Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'indirect': 0.84; 'received:74.208.4.194': 0.84; 'spawned': 0.84; 'thing,': 0.84; 'angel': 0.93 Date: Sat, 21 Jul 2012 18:33:05 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: Bruce Sherwood Subject: Re: A thread import problem References: <87a9yt7bw6.fsf@handshake.de> <500AD83B.1090403@davea.name> <500B16C9.6070608@davea.name> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:IiA05mAZsMnrQ0B8SB2A1tunAp4+RaKTWppwaEmxVsB ngbRvG8YJnvMVfzEOwoFM6EtRvWXW9lGmflWnkQXm4TFQMyM9A 7pwbTRO2ABlreiK34MtulXfg35yJlj88RsaAfKy4O0wAPVOcYZ 5IMJyAQqe4RrSH6aoF/AGvFoiId90iLLrPNL5wUbB7aQiTkbW/ QZyt9KjZqvmF8QPbknNlNwNUPBFrm2mdGpSu7PuSsCZkR7nDwj ACMMxEbrP0k703Rqq4gf4rWx4mjb5X8dxD+02zpEonFUM7C25E Apu21GtnDa1sn8rgkhsmVz2NzqhHBcaKs15VbYv9VXghuMrsg= = Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name 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: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342910010 news.xs4all.nl 6882 [2001:888:2000:d::a6]:47710 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25774 On 07/21/2012 05:35 PM, Bruce Sherwood wrote: > On Sat, Jul 21, 2012 at 2:53 PM, Dave Angel wrote: >> >> For docs on the threading thing, see: >> >> http://docs.python.org/library/threading.html >> >> " ... an import should not have the side effect of spawning a new thread >> and then waiting for that thread in any way..." >> >> >> >> >> -- >> >> DaveA >> > Thanks. I had read that as forbidding "waiting for that thread", not > forbidding spawning a new thread. The following sentence says, > "Failing to abide by this restriction can lead to a deadlock if the > spawned thread directly or indirectly attempts to import a module." I > gather that a clearer, more forceful statement might be, "Failing to > abide by this restriction WILL lead to a deadlock if the spawned > thread directly or indirectly attempts to import a module." All of > which implies the behavior I've seen in various experiments, namely > that as long as the spawned thread doesn't do any imports, I haven't > seen any problems with spawning a thread in an imported module. I take > your word for it that this is a no-no, but I don't know why. > > Bruce Sherwood I don't know just what will work and what will not; But there are lots of subtle and indirect ways of "waiting for that thread" and I suspect that import is one of them. Since I've never seen a case where we had to break the general rule, it just seems easier to keep it clean. No threading inside an import. Same with recursive imports. I could list some of the specific problems that crop up, but since the only time recursive imports are unavoidable is when you're constrained by preexisting 3rd party software that does something strange, it seems easier to make a simple rule that's easy enough to test for. if you try to import the script (that imported you) as though it were a module, you end up with two copies of that module, and if they have any non-constant globals, you can get very strange symptoms. In other recursion cases, -- DaveA