Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.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; 'importing': 0.04; 'defines': 0.07; 'finished.': 0.07; 'api': 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; 'spawn': 0.09; 'def': 0.10; 'properly': 0.15; 'sat,': 0.15; '"called"': 0.16; '0.001': 0.16; 'deferred': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:import': 0.16; 'threads': 0.16; 'true:': 0.16; 'vpython': 0.16; 'tries': 0.17; 'thanks,': 0.18; 'module': 0.19; 'putting': 0.20; 'import': 0.21; 'lets': 0.22; 'subject:problem': 0.22; 'bruce': 0.23; "i've": 0.23; '(as': 0.27; 'header:X-Complaints-To:1': 0.28; 'invoke': 0.29; 'wrap': 0.29; "i'm": 0.29; 'function': 0.30; 'stuff': 0.30; '(and': 0.32; 'running': 0.32; 'url:home': 0.33; 'handle': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; "can't": 0.34; 'received:org': 0.36; 'but': 0.36; 'loaded': 0.36; 'visual': 0.36; 'anything': 0.36; 'charset:us-ascii': 0.36; 'does': 0.37; 'level': 0.37; 'being': 0.37; 'far': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'solve': 0.62; 'jul': 0.65; 'dennis': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: A thread import problem Date: Sat, 21 Jul 2012 19:47:13 -0400 Organization: > Bestiaria Support Staff < References: <87a9yt7bw6.fsf@handshake.de> <2u8m085co3j3n97jorkl04o5hr1orqb7la@invalid.netcom.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-249-19-203.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342914432 news.xs4all.nl 6970 [2001:888:2000:d::a6]:33055 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25778 On Sat, 21 Jul 2012 17:10:05 -0600, Bruce Sherwood declaimed the following in gmane.comp.python.general: > Thanks, but the problem I need to solve does not permit putting a > function like runner in the main program. I'm constrained to being > able to handle the API of VPython (vpython.org), which lets you write > programs like the following (call it user.py), which animates a 3D > cube moving to the right, using OpenGL: > > from visual import box > b = box() > while True: > b.pos.x += 0.001 Well, based on that sample, wrap THAT as "runner" def runner(): from visual import box b = box() while True: b.pos.x += 0.0001 and don't /call/ runner() until after all the main system is configured. (And runner could, if need be, be "called" as a thread). Not having a Mac, I can't do tests... but everything I've seen so far comes down to NOT IMPORTING anything that tries to spawn threads /during the import/. A properly designed module (as I showed with my testABA.py) only "runs" stuff if loaded as the main program; any other use (import) only does imports and defines module level entities -- running anything is deferred for the program that did the import to invoke AFTER the import finished. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/