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


Groups > comp.lang.python > #25771

Re: A thread import problem

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <bruce.sherwood@gmail.com>
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; 'initialize': 0.05; '21,': 0.07; 'function,': 0.07; 'see:': 0.07; 'constants.': 0.09; 'imported': 0.09; 'indirectly': 0.09; 'received:mail- vc0-f174.google.com': 0.09; 'restriction': 0.09; 'script,': 0.09; 'sentence': 0.09; 'thread': 0.11; 'sat,': 0.15; 'deadlock': 0.16; 'exceptions.': 0.16; "module's": 0.16; 'statement.': 0.16; 'subject:import': 0.16; 'suggestion.': 0.16; 'thread.': 0.16; 'threading': 0.16; 'threads': 0.16; 'top-level': 0.16; 'wrote:': 0.17; 'pointed': 0.17; 'why.': 0.17; '>>>': 0.18; 'module': 0.19; 'issue.': 0.20; 'pending': 0.20; 'import': 0.21; 'thanks.': 0.21; 'subject:problem': 0.22; '(you': 0.23; 'bruce': 0.23; 'statement': 0.23; "haven't": 0.23; "i've": 0.23; 'script': 0.24; 'header:In- Reply-To:1': 0.25; 'am,': 0.27; 'module.': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'description,': 0.29; 'gather': 0.29; 'implies': 0.29; 'received:209.85.220.174': 0.29; "i'm": 0.29; 'function': 0.30; 'figure': 0.30; 'code': 0.31; 'url:python': 0.32; 'docs': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'clear': 0.35; 'pm,': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'should': 0.36; 'problems': 0.36; 'possible': 0.37; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'things': 0.38; 'nothing': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'little': 0.39; 'header:Received:5': 0.40; 'end': 0.40; 'your': 0.60; 'side': 0.61; 'more': 0.63; 'behavior': 0.64; 'making': 0.64; 'harder': 0.65; 'jul': 0.65; 'special': 0.73; 'spawned': 0.84; 'thing,': 0.84; 'angel': 0.93
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:to :content-type; bh=vulRfpnxQqe3Ti0BK7oMzFRkjMDdvI1Uxk8+FEKPJRk=; b=GZACfwGD2jeLqGt/L8fZpbIqGNLOyhPFZBaqkT+IAfCO2ZAvfGO9H7PRz9f5zNyLcA 6BhdooS3M7hWxQ6E2MHIiBUBJbzWDJDF41JCUw1+c50yusUSFyhP/oSrXSRo6nmPiqzI wgT1CDmb1NR1DpBkN+G3fwlYdLhl4SECyz1omwKlUSmNcCF5QCShcpOt1OZPaw/dw+fj B1ngE/BhJ2WaVfO1YTA6h7A5kBv2S6BWNNockthQOi9uukVmS5Tf/ubH8k5h0AkMHEul LVkmKHFRTPrCeEY/jakBWKCcvqaT/zIgRrkoXxeV86CWhMdok3OyD4MnvKDRY2NdEG52 yLWQ==
MIME-Version 1.0
In-Reply-To <500B16C9.6070608@davea.name>
References <CA+WuaScBDU_5LcrCrTtDr6N3gHCk9hQ03fA=DT359GCRY=a=KQ@mail.gmail.com> <CA+WuaSeRExxaD9yCNWhXoWqsV_ZqP8DOvdErMRdNS-H_UtzQyg@mail.gmail.com> <87a9yt7bw6.fsf@handshake.de> <CA+WuaSc1wzUqUyw_=QqryN2H_FKYqxspnuqBWECVq5-DH2Lcvg@mail.gmail.com> <500AD83B.1090403@davea.name> <CA+WuaSdcBk+0jyT2P_RUo=AjPSSm-VQzRG7ENiy4ZsdjzVqT9g@mail.gmail.com> <500B16C9.6070608@davea.name>
Date Sat, 21 Jul 2012 15:35:26 -0600
Subject Re: A thread import problem
From Bruce Sherwood <bruce.sherwood@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2400.1342906533.4697.python-list@python.org> (permalink)
Lines 64
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1342906534 news.xs4all.nl 6909 [2001:888:2000:d::a6]:58823
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25771

Show key headers only | View raw


On Sat, Jul 21, 2012 at 2:53 PM, Dave Angel <d@davea.name> wrote:
> On 07/21/2012 04:36 PM, Bruce Sherwood wrote:
>> Thanks much for this clear statement. I hadn't managed to find any
>> documentation on this specific issue.
>>
>> Bruce Sherwood
>>
>> On Sat, Jul 21, 2012 at 10:26 AM, Dave Angel <d@davea.name> wrote:
>>> Two of the things you mustn't do during an import:
>>>
>>> 1) start or end any threads
>>> 2) import something that's already in the chain of pending imports.
>>> (otherwise known as recursive imports, or import loop).  And there's a
>>> special whammy reserved for those who import the script as though it
>>> were a module.
>>>
>>> Like any rule, there are possible exceptions.  But you're much better
>>> off factoring your code better.
>>>
>>> I haven't managed to understand your software description, so i'm not
>>> making a specific suggestion.  But I know others have pointed out that
>>> you should do as little as possible in top-level code of an imported
>>> module.  Make the work happen in a function, and call that function from
>>> the original script, not from inside some import.  An imported module's
>>> top-level code should do nothing more complex than initialize module
>>> constants.
>>>
>>>
>>> --
>>>
>>> DaveA
>>>
>>>
>
> (You top-posted, which makes it harder to figure out who said what.)
>
> 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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: A thread import problem Bruce Sherwood <bruce.sherwood@gmail.com> - 2012-07-21 15:35 -0600

csiph-web