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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'interpreter': 0.04; 'concurrently': 0.07; 'python': 0.09; 'block.': 0.09; 'blocked': 0.09; 'imported': 0.09; 'imports': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'looked': 0.10; 'gui': 0.11; 'thread': 0.11; '(something': 0.16; 'deadlock': 0.16; 'modules,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:import': 0.16; 'thread.': 0.16; 'threads': 0.16; 'holds': 0.20; 'import': 0.21; 'subject:problem': 0.22; 'bruce': 0.23; 'seems': 0.23; 'header:User-Agent:1': 0.26; 'common': 0.26; 'header:X-Complaints-To:1': 0.28; '"in': 0.29; 'locking': 0.29; 'locks': 0.29; 'writes:': 0.29; "i'm": 0.29; 'problem': 0.33; 'to:addr:python-list': 0.33; 'doing': 0.35; 'something': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'test': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'problems': 0.36; 'uses': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'to:addr:python.org': 0.39; 'easily': 0.39; 'header:Received:5': 0.40; "you'll": 0.62; 'dangerous': 0.66; 'received:217': 0.68; 'protect': 0.69; 'introduce': 0.80; 'wrong!': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dieter Maurer Subject: Re: A thread import problem Date: Sun, 22 Jul 2012 08:18:44 +0200 References: <87a9yt7bw6.fsf@handshake.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gmane-NNTP-Posting-Host: pd9e08f42.dip0.t-ipconnect.de User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) Cancel-Lock: sha1:iBlHZW27pHy6ENUHRuNr+ZaUXvM= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342937938 news.xs4all.nl 6984 [2001:888:2000:d::a6]:47720 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25796 Bruce Sherwood writes: > ... > The failure of this test case suggests that one cannot do imports > inside secondary threads started in imported modules, something I keep > tripping over. But I hope you'll be able to tell me that I'm doing > something wrong! As you know multiple threads can be dangerous when they concurrently change common data structures. Locks are used to protect those data structures. Locking can introduce other problems - like deadlocks (something you seem to observe). I have not looked at the concrete implementation. However, the Python documentation suggests that the import machinery uses its own locks (beside the "Global Interpreter Lock"). It seems to be a "thread lock", which would mean that a thread is not blocked when it already holds the lock - however any other thread would block. This easily can lead to a deadlock -- when you wait for the other thread "in any way". There should be no problem when you complete the whole import chain without any waiting for the thread. However, should you start the GUI main loop inside the import chain, you will never complete this chain.