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


Groups > comp.lang.python > #25750

Re: A thread import problem

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'initialize': 0.05; 'function,': 0.07; 'constants.': 0.09; 'imported': 0.09; 'script,': 0.09; 'cc:addr:python-list': 0.10; '"your': 0.16; 'exceptions.': 0.16; "module's": 0.16; 'subject:import': 0.16; 'suggestion.': 0.16; 'threads': 0.16; 'top-level': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'pointed': 0.17; 'module': 0.19; 'pending': 0.20; 'import': 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; '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; 'skip:" 20': 0.26; 'am,': 0.27; 'module.': 0.27; 'initial': 0.28; 'description,': 0.29; 'occurred': 0.29; "i'm": 0.29; 'function': 0.30; 'code': 0.31; 'thanks': 0.34; "won't": 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'should': 0.36; 'possible': 0.37; 'correctly': 0.37; 'execute': 0.37; 'two': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'some': 0.38; 'things': 0.38; 'nothing': 0.38; 'sure': 0.38; 'received:192': 0.39; 'little': 0.39; 'received:192.168': 0.40; 'end': 0.40; 'your': 0.60; 'more': 0.63; 'making': 0.64; 'header:Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'special': 0.73
Date Sat, 21 Jul 2012 12:26:35 -0400
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0
MIME-Version 1.0
To Bruce Sherwood <bruce.sherwood@gmail.com>
Subject Re: A thread import problem
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>
In-Reply-To <CA+WuaSc1wzUqUyw_=QqryN2H_FKYqxspnuqBWECVq5-DH2Lcvg@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:Fx+PpkmqvPnXkGTaMFCFZXwhANxghec5fdAKUDVOeFQ rNpOCM3em00t9I4IR13XHafzGTOU5fSFq4ZWPUrNJTmAs/Grry DR6I28W8mYRNtXpXdg2ko/F/9gp0qhW05M2lKZ3UwcyEB61laA 6ZIQHHgisvmGJLtsDJbs722GHiDJgm0gX2eIHl/2ntXJmIm+f7 cwoodv0HuWTmTKqusi0VCAt57rhXdaIIsor90YW3hlqZ7tfcme w3ByYB3PzH5sumNGOjo3YL+a/zc2kRS11+9hACDj3xKbDbNRnU C4r+i72TBkqUEdHvtLCrvf0NJjLYe3cGdHDU0RdGSBfdMCfZw= =
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 <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.2388.1342888031.4697.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1342888031 news.xs4all.nl 6889 [2001:888:2000:d::a6]:36651
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25750

Show key headers only | View raw


On 07/21/2012 10:54 AM, Bruce Sherwood wrote:
> Thanks much for this suggestion. I'm not sure I've correctly
> understood the operation "start_new_thread(lambda: __import__(<your
> module>), ())". By "your module" do you mean the user program which
> imported the module that will execute start_new_thread? It hadn't
> occurred to me to have A import B and B import A, though now that you
> describe this (if that's indeed what you mean) it makes sense. The
> original instance of A won't get past its initial import statement
> because the main loop won't return to it.
>
> Bruce Sherwood
>

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

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


Thread

Re: A thread import problem Dave Angel <d@davea.name> - 2012-07-21 12:26 -0400

csiph-web